Skip to main content

file open from nested zip file archive.

Project description

zip_open open file from nested zip file archive.

If you use static file like as ‘data.zip’ and open this from your python code, Your program will become like open(os.path.join(os.path.dirname(__file__), 'data.zip')). But if your packages are packed into packages.zip file (zipped-egg, or cases to gather in one file on Google App Engine matter), your cord doesn’t work fine.

In this situation, the file path of data.zip becomes /path/to/packages.zip/data.zip, then your program can’t open the data.zip file.

zip_open package solves this problem.

Features

  • Open file from nested zip file archive.

Using sample1: open the file from zip file

packages1.zip is:

packages1.zip
  + file1.txt

Open file1.txt:

>>> from zip_open import zopen
>>> fobj = zopen('packages1.zip/file1.txt')
>>> data = fobj.read()
>>> print data
I am file1.txt, ok.

This code sample equivalent to below code:

>>> from zipfile import ZipFile
>>> zipobj = ZipFile('packages1.zip')
>>> data = zipobj.read('file1.txt')
>>> print data
I am file1.txt, ok.

Using sample2: open the file from nested zip file

packages2.zip is:

packages2.zip
  + data2.zip
     + file2.txt

Open file2.txt:

>>> from zip_open import zopen
>>> fobj = zopen('packages2.zip/data2.zip/file2.txt')
>>> print fobj.read()
I am file2.txt, ok.

Using sample3: open the file included in package oneself

packages3.zip is:

packages3.zip
  + foo.py
  + file1.txt
  + data3.zip
     + file3.txt

foo.py:

import os
from zip_open import zopen

def loader(filename):
    fobj = zopen(os.path.join(os.path.dirname(__file__), filename))
    return fobj

execute loader() from interactive shell:

>>> import sys
>>> sys.path.insert(0, 'packages3.zip')
>>> import foo
>>> fobj = foo.loader('file1.txt')
>>> print fobj.read()
I am file1.txt, ok.
>>> fobj = foo.loader('data3.zip/file3.txt')
>>> print fobj.read()
I am file3.txt, ok.

Requirements and dependencies

  • Requirement: Python 2.4 or later

  • Dependency: Nothing.

ToDo

  • Add module import feature.

History

0.1.0 (2010-7-19)

  • first release

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

zip_open-0.1.0.zip (7.7 kB view details)

Uploaded Source

File details

Details for the file zip_open-0.1.0.zip.

File metadata

  • Download URL: zip_open-0.1.0.zip
  • Upload date:
  • Size: 7.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for zip_open-0.1.0.zip
Algorithm Hash digest
SHA256 eff9bdbbeb8ba644118a338a50a2270159582e6b86f5791a892447608d0cb68e
MD5 afe474ae888b11149082d2e022a97d6b
BLAKE2b-256 e21f3f0fc775f9a4927255a813383545e62e55b3219b9ceee635b55e6cccd21e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page