background preloader

Compressing-zlig-tzrfile-gzlib

Facebook Twitter

Packaging Python Libraries - Dive Into Python 3 - Iceweasel. How to Zip a Directory with Python (using zipfile) - Python - Iceweasel. I'm relatively new to python, and am trying to zip a directory containing several levels of files and folders. I can use the walk function to name each file in my directory, and I can use zipfile to zip a flat number of files in one folder, but I am having heck of a time trying to zip the whole directory.

I want to zip it all to a file called "help.zip", and I want it to retain the original file structure. Of my several tries, here is the latest: The zipfile module - Iceweasel. (New in 2.0) This module allows you to read and write files in the popular ZIP archive format. Listing the contents To list the contents of an existing archive, you can use the namelist and infolist methods. The former returns a list of filenames, the latter a list of ZipInfo instances. Example: Using the zipfile module to list files in a ZIP file # File: zipfile-example-1.py import zipfile file = zipfile.ZipFile("samples/sample.zip", "r") # list filenames for name in file.namelist(): print name, print # list file information for info in file.infolist(): print info.filename, info.date_time, info.file_size $ python zipfile-example-1.py sample.txt sample.jpg sample.txt (1999, 9, 11, 20, 11, 8) 302 sample.jpg (1999, 9, 18, 16, 9, 44) 4762 Reading data from a ZIP file To read data from an archive, simply use the read method.

Example: Using the zipfile module to read data from a ZIP file $ python zipfile-example-2.py sample.txt 302 'We will pe' sample.jpg 4762 '\377\330\377\340\000\020JFIF' Unzip - Unzipping directory structure with python - Stack Overflow - Iceweasel. LZMA SDK (Software Development Kit) - Iceweasel. PyLZMA » ~magog/public - Iceweasel. Platform independent python bindings for the LZMA compression library.

Impressed by the spectacular compression ratios of the Inno Setup compiler, I wanted to use the great compression algorithm LZMA in my own Python programs. As the LZMA SDK by Igor Pavlov is Open Source, it was no problem writing some Python wrappers for the C library. They currently run fine both on Windows and Linux, so hopefully, I can provide a tool that enables the user to read and create 7-zip compatible archives on Linux (as this is not supported by the original 7-zip). Here are the compression results of different data files with the zlib, bz2 and pylzma modules: Depending on your input data, the differences between zlib/bz2 and pylzma may be even bigger!

You can download the binaries and the source code for the wrappers from the Python Package Index. For building, simply run: python setup.py build If you installed the EasyInstall package, you can install the latest version of pylzma using the following command: Pylzma 0.4.4 : Python Package Index - Iceweasel. Package Index > pylzma > 0.4.4 Not Logged In Status Nothing to report pylzma 0.4.4 Downloads ↓ Python bindings for the LZMA library by Igor Pavlov.

PyLZMA provides a platform independent way to read and write data that has been compressed or can be decompressed by the LZMA library by Igor Pavlov. Downloads (All Versions): 68 downloads in the last day 932 downloads in the last week 3345 downloads in the last month Website maintained by the Python community Real-time CDN by Fastly / hosting by Rackspace / design by Tim Parkin. Zip and Unzip an Archieve of Files (Python) - Python - Iceweasel. Iceweasel. Python - Chapter 33. File Handling Modules - Iceweasel. Chapter 33. File Handling Modules There are a number of operations closely related to file processing. Deleting and renaming files are examples of operations that change the directory information that the operating system maintains to describe a file. Python provides numerous modules for these operating system operations. We can't begin to cover all of the various ways in which Python supports file handling.

The following modules have features that are essential for supporting file processing. Chapter 11 - File and Directory Access. Os.path Common pathname manipulations. Os Miscellaneous OS interfaces. Fileinput This module has functions which will iterate over lines from multiple input streams. Tempfile Generate temporary files and temporary file names. glob UNIX shell style pathname pattern expansion. Fnmatch UNIX shell style filename pattern matching. Shutil High-level file operations, including copying and removal. Chapter 12 - Data Compression and Archiving.

Tarfile, zipfile zlib, gzip, bz2. Python - The File Archive Modules: tarfile and zipfile - Iceweasel. An archive file contains a complex, hierarchical file directory in a single sequential file. The archive file includes the original directory information as well as a the contents of all of the files in those directories. There are a number of archive file formats, Python directory supports two: tar and zip archives. The tar (Tape Archive) format is widely used in the GNU/Linux world to distribute files.

It is a POSIX standard, making it usable on a wide variety of operating systems. The Zip file format was invented by Phil Katz at PKWare as a way to archive a complex, hierarchical file directory into a compact sequential file. Creating a TarFile or a ZipFile. Tarfile.open〈name〉〈mode〉〈fileobj〉〈buffersize〉 → TarFile This module-level function opens the given tar file for processing. Zipfile. This class constructor opens the given zip file for processing. The open function can be used to read or write the archive file. Opening - Both zip and tar files.

R Open the file for reading. w a (nothing) Python - The Data Compression Modules: zlib, gzip, bz2 - Iceweasel. The zlib, gzip and bz2 modules provide essential data and file compression tools. Data files are often built for speedy processing, and may contain characters which are meaningless spacing. This extraneous data can be reduced in size, or compressed.

For example, a .tar file is often compressed using GZip to create a .tar.gz file, sometimes called a .tgz file. In the case of the ZIP file archive, the compression algorithms are already part of the zipfile module. These modules are very flexible and can be used in a variety of ways by an application program. Data Compression and Decompression. Note that the interfaces for the zlib and bz2 modules are designed to be nearly identical. Zlib.compress(string, 〈level〉) → string Compress the given string. Zlib.decompress(string → string) Decompress the given string. bz2.compress → string Compress the given string. Bz2.decompress → string zlib.adler32(string) → number Compute the 32-bit Adler checksum of the given string. zlib.crc32(string → number) d.