cl-octet-streams

2020-12-20

In-memory octet streams

Upstream URL

github.com/glv2/cl-octet-streams

Author

Guillaume LE VAILLANT

License

GPL-3
README
cl-octet-streams

cl-octet-streams is a library implementing in-memory octet streams for Common Lisp. It was inspired by the trivial-octet-streams and cl-plumbing libraries.

1Installation

The only dependency is the trivial-gray-streams library.

2API

2.1Input stream

(make-octet-input-stream seq &optional (start 0) end) => stream

Return an input stream which will supply the bytes of seq between start and end in order.

(with-octet-input-stream (var seq &optional (start 0) end) &body body)

Within body, var is bound to an octet input stream defined by seq, start and end. The result of the last form of body is returned.

2.2Output stream

(make-octet-output-stream) => stream

Return an output stream which will accumulate all the bytes written to it for the benefit of the function get-output-stream-octets.

(get-output-stream-octets stream) => bytes

Return the bytes that were written to an octet output stream.

(with-octet-output-stream (var) &body body) => bytes

Within body, var is bound to an octet output stream. After all the forms in body have been executed, the bytes that have been written to var (and that haven't been consumed by a call to get-output-stream-octets within body) are returned.

2.3Pipe

(make-octet-pipe) => stream

Return a stream which will supply the bytes that have been written to it in order.

(with-octet-pipe (var) &body body)

Within body, var is bound to an octet pipe. The result of the last form of body is returned.

2.4Connected streams

(make-connected-octet-streams) => stream1, stream2

Return two streams connected to each other. The bytes written to the first stream can be read from the second, and the bytes written to the second stream can be read from the first.

(with-connected-octet-streams (var1 var2) &body body)

Within body, var1 and var2 are bound to octet streams connected to each other. The result of the last form of body is returned.

2.5Extra functions

The following functions can be used on input streams, output streams and pipes.

(octet-stream-length stream) => integer

Return the number of bytes available in stream.

(octet-stream-ref stream index) => byte

Return the byte at index in stream.

(octet-stream-search stream pattern jump-table) => index or nil

Search pattern in the bytes of stream using the Boyer-Moore algorithm. The jump-table must be 256 bytes long. If there is a match, return the index of the beginning of the pattern in the stream, otherwise return nil.

(make-jump-table pattern) => array

Return a jump table for pattern that can be used with octet-stream-search.

3Tests

The tests require the fiveam library.

(asdf:test-system "cl-octet-streams")

Dependencies (2)

  • fiveam
  • trivial-gray-streams

Dependents (2)

  • GitHub
  • Quicklisp