Skip to main content

Facilities to do with buffers, primarily CornuCopyBuffer, an automatically refilling buffer to support parsing of data streams.

Project description

Facilities to do with buffers, primarily CornuCopyBuffer, an automatically refilling buffer to support parsing of data streams.

Function chunky(bfr_func)

Decorator for a function accepting a leading CornuCopyBuffer parameter. Returns a function accepting a leading data chunks parameter (bytes instances) and optional offset and 'copy_offsets` keywords parameters.

Example::

@chunky def func(bfr, ...):

Class CopyingIterator

Wrapper for an iterator that copies every item retrieved to a callable.

Class CornuCopyBuffer

An automatically refilling buffer intended to support parsing of data streams.

Attributes:

  • buf: a buffer of unparsed data from the input, available for direct inspection by parsers
  • offset: the logical offset of the buffer; this excludes unconsumed input data and .buf

The primary methods supporting parsing of data streams are extend() and take(). Calling .extend(min_size) arranges that .buf contains at least min_size bytes. Calling .take(size) fetches exactly size bytes from .buf and the input source if necessary and returns them, adjusting .buf.

len(CornuCopyBuffer) returns the length of .buf.

bool(CornuCopyBuffer) tests whether len() > 0.

Indexing a CornuCopyBuffer accesses .buf.

A CornuCopyBuffer is also iterable, yielding data in whatever sizes come from its input_data source, preceeded by the current .buf if not empty.

A CornuCopyBuffer also supports the file methods .read, .tell and .seek supporting drop in use of the buffer in many file contexts. Backward seeks are not supported. .seek will take advantage of the input_data's .seek method if it has one, otherwise it will use reads.

Class SeekableFDIterator

An iterator over the data of a file descriptor.

Class SeekableFileIterator

An iterator over the data of a file object.

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

cs.buffer-20180805.tar.gz (7.6 kB view details)

Uploaded Source

File details

Details for the file cs.buffer-20180805.tar.gz.

File metadata

  • Download URL: cs.buffer-20180805.tar.gz
  • Upload date:
  • Size: 7.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.23.0 CPython/3.6.6

File hashes

Hashes for cs.buffer-20180805.tar.gz
Algorithm Hash digest
SHA256 77346047c0a0cdabe4569a7baa43b2fded7c1fef3a541d7e9efcdd07fd0f242d
MD5 a576c2ba32084764549157f6f6ba882b
BLAKE2b-256 40d5ceffdbe3bdb6ea5ddafcc6820a82e595864c0556dd62bb6b9d90b0e73a06

See more details on using hashes here.

Supported by

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