473,563 Members | 2,732 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is there a Python library that packs binary data into one file?

Hello all,

Today I began writing a utility script that takes given binary files
and puts them all into one datafile. My idea is to be able to access
any binary data I want by indexing the datafile, e.g.
wanted_image_da ta = datafileobj[IMAGE_DATA]. The purpose is to hide
external image files from the user in a simple game I'm writing.

Though I have a good idea of how to implement this, before I begin I
am curious to know if some Python master out there has already come
out with a library that does the same. Anyone? :)
Jul 18 '05 #1
5 1909
zipfile.py works pretty well and you get compression
as well.

Larry Bates
Syscon, Inc.

"Jacob H" <ja********@pos tmark.net> wrote in message
news:85******** *************** ***@posting.goo gle.com...
Hello all,

Today I began writing a utility script that takes given binary files
and puts them all into one datafile. My idea is to be able to access
any binary data I want by indexing the datafile, e.g.
wanted_image_da ta = datafileobj[IMAGE_DATA]. The purpose is to hide
external image files from the user in a simple game I'm writing.

Though I have a good idea of how to implement this, before I begin I
am curious to know if some Python master out there has already come
out with a library that does the same. Anyone? :)

Jul 18 '05 #2
>>>>> "Jacob" == Jacob H <ja********@pos tmark.net> writes:

Jacob> Hello all, Today I began writing a utility script that
Jacob> takes given binary files and puts them all into one
Jacob> datafile. My idea is to be able to access any binary data I
Jacob> want by indexing the datafile, e.g. wanted_image_da ta =
Jacob> datafileobj[IMAGE_DATA]. The purpose is to hide external
Jacob> image files from the user in a simple game I'm writing.

Jacob> Though I have a good idea of how to implement this, before
Jacob> I begin I am curious to know if some Python master out
Jacob> there has already come out with a library that does the
Jacob> same. Anyone? :) --

How about putting it into a tar file? There are many archive file
formats (ISO9960, tar, zip). You could just reuse one of these and an
existing python interface to them, compressing and encrypting as
necessary if you need extra obscurity.

JDH
Jul 18 '05 #3
Jacob H wrote:
Hello all,

Today I began writing a utility script that takes given binary files
and puts them all into one datafile. My idea is to be able to access
any binary data I want by indexing the datafile, e.g.
wanted_image_da ta = datafileobj[IMAGE_DATA]. The purpose is to hide
external image files from the user in a simple game I'm writing.

What you need, is a simple pickle of a dictionary save to disk.

It's dead easy, and does exactly what you want.

import cPickle

some_dict = {'my':'name','i s':'norman','ba tes':'!'}
file_name = 'some.dict'

f = open(file_name, 'wb')
cPickle.dump(so me_dict, f, -1)
f.close()

f = open(file_name, 'rb')
c = cPickle.load(f)
f.close()

print c
{'my': 'name', 'is': 'norman', 'bates': '!'}

"
3.14 pickle -- Python object serialization

The pickle module implements a fundamental, but powerful algorithm for
serializing and de-serializing a Python object structure. ``Pickling''
is the process whereby a Python object hierarchy is converted into a
byte stream, and ``unpickling'' is the inverse operation, whereby a byte
stream is converted back into an object hierarchy. Pickling (and
unpickling) is alternatively known as ``serialization '',
``marshalling,' '3.2 or ``flattening'', however, to avoid confusion, the
terms used here are ``pickling'' and ``unpickling''.

This documentation describes both the pickle module and the cPickle module.
"

regards Max M
Jul 18 '05 #4
Jacob H wrote:
Hello all,

Today I began writing a utility script that takes given binary files
and puts them all into one datafile. My idea is to be able to access
any binary data I want by indexing the datafile, e.g.
wanted_image_d ata = datafileobj[IMAGE_DATA]. The purpose is to hide
external image files from the user in a simple game I'm writing.

Though I have a good idea of how to implement this, before I begin I
am curious to know if some Python master out there has already come
out with a library that does the same. Anyone? :)

Not quite what you're asking for, but ResourcePackage embeds resources
automatically in Python files. If you are py2exe'ing your projects the
result is that the images are invisible (they are part of the Python
bytecode files py2exe packs into the exe). The nice part is the
automation; you just update the data-file (stored in a sub-package of
your main game package) and the embedded version is automagically
updated on next import of the resource package (run of the game).

http://resourcepackage.sf.net/

Have fun,
Mike

_______________ _______________ _________
Mike C. Fletcher
Designer, VR Plumber, Coder
http://members.rogers.com/mcfletch/

Jul 18 '05 #5
Jacob H wrote:
Hello all,

Today I began writing a utility script that takes given binary files
and puts them all into one datafile. My idea is to be able to access
any binary data I want by indexing the datafile, e.g.
wanted_image_da ta = datafileobj[IMAGE_DATA]. The purpose is to hide
external image files from the user in a simple game I'm writing.


In the vein of giving a man a fish: if you are using python 2.2+

import dbhash, zlib

db = dbhash.open("fo o.db", 'w')

db['hi'] = zlib.compress(" my dog has fleas")
print zlib.decompress (db['hi'])

for more help
type

help(dbhash)

at the interpreter

In the vein of teaching a man to fish, read the library reference here
for a lot of python goodies:

http://python.org/doc/2.3.3/lib/

Brian
Jul 18 '05 #6

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

Similar topics

10
3670
by: Andrew Dalke | last post by:
Is there an author index for the new version of the Python cookbook? As a contributor I got my comp version delivered today and my ego wanted some gratification. I couldn't find my entries. Andrew dalke@dalkescientific.com
2
4433
by: ajikoe | last post by:
Hi, I tried to follow the example in swig homepage. I found error which I don't understand. I use bcc32, I already include directory where my python.h exist in bcc32.cfg. /* File : example.c */ #include <time.h>
4
3129
by: Arnaud Delobelle | last post by:
Hi fellow python enthusiasts. Having recently acquired a MacBook Pro (Intel Core 2 Duo) which comes with python2.5, I have been installing some modules that I need (PIL, psycopg2, PyXML ...). The problem is that compiles all the binaries to universal files for i386 and ppc32, but not x86_64 or ppc64. It does not appear to be a problem...
20
2428
by: Mr.SpOOn | last post by:
Hi, I need a structure to represent a set of integers. I also need to perform on this set some basic set operations, such as adding or removing elements, joining with other sets and checking for the presence of specific elements. I think that using Python sets would be the best choice, but I also need integers to be ordered inside the set...
0
8106
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7638
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6250
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3642
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2082
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1198
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
923
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.