cramjam
Common base class for all non-exit exceptions.
Common base class for all non-exit exceptions.
A native Rust file-like object. Reading and writing takes place through the Rust implementation, allowing access to the underlying bytes in Python.
Python Example
from cramjam import File
file = File("/tmp/file.txt")
file.write(b"bytes")
Notes
Presently, the file's handle is managed by Rust's lifetime rules, in that once it's garbage collected from Python's side, it will be closed.
Write some bytes to the file, where input data can be anything in BytesType
Read from the file in its current position, returns bytes
; optionally specify number of
bytes to read.
Seek to a position within the file. whence
follows the same values as IOBase.seek
where:
0: from start of the stream
1: from current stream position
2: from end of the stream
Whether the file is seekable; here just for compatibility, it always returns True.
A native Rust file-like object. Reading and writing takes place through the Rust implementation, allowing access to the underlying bytes in Python.
Python Example
>>> from cramjam import Buffer
>>> buf = Buffer(b"bytes")
>>> buf.read()
b'bytes'
NOTE: Use copy=False
responsibly! That is to say, it will not
copy the data, and will be referencing the underlying buffer during this
Buffer's lifetime. We make an attempt to realign each time when accessing
the buffer, but one should broadly take care to use locks where neccessary.
Internally we increment the PyObject ref count, so it should be free
from said buffer being garbage collected out from under us, but do try to
avoid any funny business. :)
copy=False
is not supported on PyPy distributions
When the underlying buffer view has maybe changed, call this to realign it according to the object we're referencing. Has no effect if Buffer has owned data or if it's determined no change has occurred, by comparing pointer and length.
Get the PyObject this Buffer is referencing as its view, returns None if this Buffer owns its data.
Get the PyObject reference count this Buffer is referencing as its view, returns None if this Buffer owns its data.
Write some bytes to the buffer, where input data can be anything in BytesType
Read from the buffer in its current position, returns bytes; optionally specify number of bytes to read.
Read from the buffer in its current position, into a BytesType object.
Seek to a position within the buffer. whence follows the same values as IOBase.seek where:
0: from start of the stream
1: from current stream position
2: from end of the stream
Whether the buffer is seekable; here just for compatibility, it always returns True.