greglook / clj-cbor

Native Clojure CBOR codec implementation.
The Unlicense
70 stars 7 forks source link

Support streaming writes #17

Open greglook opened 4 years ago

greglook commented 4 years ago

CBOR supports a notion of streamed data, where instead of being prefixed, a collection is marked as being a stream. The reader is expected to read elements off the stream until they see the special break value. The codec currently supports reading streamed data, but has no way to write it.

The most obvious place to support streaming is when we encounter lazy sequences or other values which are Iterable and don't match any other handlers. Lazy sequences are currently fully realized to count them before writing any data, which may be undesirable. This could be controlled by a new codec option.

Streaming map support is a little trickier, and it's not clear that it's actually valuable to support yet. This could be accomplished with a wrapper type though, which held an iterable value and indicated that it should expect to read key/value pairs and write out a streaming CBOR map.