472,805 Members | 1,073 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,805 software developers and data experts.

memory mapped tar file contents


Hi,

I would like to read directly from a tar file into memory so I can
manipulate a file (quickly) and write its changes out to another file. I
thought I could do something like:

#!/usr/bin/env python

import tarfile
import mmap

fil = tarfile.open( "out.tar.gz" , "r:gz" )
tarinf = fil.next()
myfils = {}
while tarinf != None:
tarinf = fil.next()
ref = fil.extractfile( tarinf )
myfils[ tarinf.name ] = mmap.mmap( ref.fileno() , 0 )

But the extractfile() function of TarInfo doesn't seem to give me a fileno,
so I can't pass this to mmap.

Thoughts on a way to accomplish this?

Chris
--
View this message in context: http://www.nabble.com/memory-mapped-...p20473925.html
Sent from the Python - python-list mailing list archive at Nabble.com.

Nov 13 '08 #1
1 3775
On Nov 12, 8:51*pm, Chris Brooks <cab...@mail.usask.cawrote:
Hi,

I would like to read directly from a tar file into memory so I can
manipulate a file (quickly) and write its changes out to another file. *I
thought I could do something like:

#!/usr/bin/env python

import tarfile
import mmap

fil = tarfile.open( "out.tar.gz" , "r:gz" )
tarinf = fil.next()
myfils = {}
while tarinf != None:
* * tarinf = fil.next()
* * ref = fil.extractfile( tarinf )
* * myfils[ tarinf.name ] = mmap.mmap( ref.fileno() , 0 )

But the extractfile() function of TarInfo doesn't seem to give me a fileno,
so I can't pass this to mmap.

Thoughts on a way to accomplish this?
It appears you have to read the contents of the file into the mmap.
You can create an anonymous map of size tarinfoobj.size, then set
mapobj[:]= fil.extractfile( tarinf ).read( ) . Untested.
Nov 13 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Peter Nolan | last post by:
Hi All, I have some software that currently loads database tables into sorted arrays in memory to be binary searched by processes. (Long story as to why it does this..) Each process must either...
16
by: Justin Lazanowski | last post by:
Cross posting this question on the recommendation of an I have a .NET application that I am developing in C# I am loading information in from a dataset, and then pushing the dataset to a grid,...
18
by: jacob navia | last post by:
In C, we have read-only memory (const), read/write memory (normal data), and write only memory. Let's look at the third one in more detail. Write only memory is a piece of RAM that can only...
2
by: vikas | last post by:
I have following structure in c++. typedef struct MMF_result_struct { int action; char text; int cols,rows; int month,day,year; } MMF_result; Now this structure is shared between C++ and C#...
3
by: nkrisraj | last post by:
Hi, I have a following structure: typedef struct { RateData rdr; int RateID; char RateBalance; } RateInfo;
8
by: nkrisraj | last post by:
Hi, I have a following structure: typedef struct { RateData rdr; int RateID; char RateBalance; } RateInfo;
13
by: Samshayam | last post by:
I have come across the application of placement new in memory mapped i/o in a number of books.I am not able to understand it completely, may be becaues of my lack of knowledge with memory mapped...
12
by: Clement | last post by:
Can i place variables or arrays in Disk instead of main memory........
0
by: Chris Brooks | last post by:
Jean-Paul Calderone wrote: Actually, I want the contents of the tar uncompressed and untarred. So, for example, I might be working with image data that has to go through several...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.