Skip to main content

Classes for creating and wrapping file-like objects

Project description

The filelike module takes care of the groundwork for implementing and handling file-like objects that implement a rich file-like interface, including reading, writing, and iteration. It also provides a number of useful classes built on top of this functionality.

The main class is FileLikeBase, which implements the entire file-like interface (currently minus seek() and tell()) on top of primitive _read() and _write() methods. Subclasses may implement either or both of these methods to obtain all the higher-level file behaviors.

Two methods are provided when code expects to deal with file-like objects:

  • is_filelike(obj): checks that an object is file-like

  • to_filelike(obj): wraps a variety of objects in a file-like interface

On top of this framework are built a collection of useful classes, including:

  • TransFile: pass file contents through an arbitrary translation

    function (e.g. compression, encryption, …)

  • FixedBlockSizeFile: ensure all read/write requests are aligned with

    a given blocksize

  • DecryptFile: on-the-fly reading and writing to an encrypted file

    (using PEP272 cipher API)

As an example of the type of thing this module is designed to achieve, here’s an example of using the DecryptFile class to transparently access an encrypted file:

# Create the decryption key from Crypto.Cipher import DES cipher = DES.new(‘abcdefgh’,DES.MODE_ECB) # Open the encrypted file f = DecryptFile(file(“some_encrypted_file.bin”,”r”),cipher)

The object in <f> now behaves as a file-like object, transparently decrypting the file on-the-fly as it is read.

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

filelike-0.1.1.tar.gz (21.4 kB view details)

Uploaded Source

Built Distribution

filelike-0.1.1-py2.4.egg (1.5 kB view details)

Uploaded Source

File details

Details for the file filelike-0.1.1.tar.gz.

File metadata

  • Download URL: filelike-0.1.1.tar.gz
  • Upload date:
  • Size: 21.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for filelike-0.1.1.tar.gz
Algorithm Hash digest
SHA256 490a26b4fe055e496186d6b9f87afb3ade94a9b128362b634962476b655ed7d9
MD5 f6ec6acff0bf07d666c8f178e13b3791
BLAKE2b-256 6561f9b1bc1aa3b160fbc7f4a7c34254b099d20b42037604b5fbb346de8eb2e4

See more details on using hashes here.

File details

Details for the file filelike-0.1.1-py2.4.egg.

File metadata

File hashes

Hashes for filelike-0.1.1-py2.4.egg
Algorithm Hash digest
SHA256 b7b4ad9990f92ed1380c4d92f3fae97c68bf5035b380f4b41ed001193b62e7c9
MD5 881ae55600b5929f90cf8b5c10f20999
BLAKE2b-256 62baf5f1ad0dd7cc1467645d54bbe62d8c71f77cd09921cb2caf8e1d0fe03bdb

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