agronholm / agronholm/cbor2

Document how to handle CBOR objects concatenated in a stream

Offen
#30 5 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
documentation
Vorherrschende Sprache
Rust
Sterne
305
Forks
79
Ø Merge
21 Std. 59 Min.
Gemergte PRs (30 T.)
2

Beschreibung

An EOF while decoding should not be used to signal the end of a stream.

If you're decoding a set of CBOR objects that are just concatenated together in a file without delimiters then do this:

```python
from cbor2 import CBORDecoder
with open('myfile.cbor', 'rb') as f:
decoder = CBORDecoder(f)
while f.peek(1): # Check that there's data at the next file position
print(decoder.decode())
print('Done!')
```

Otherwise wrap the items in an indefinite length array.

This is equivalent to how you would decode cbor from a network socket or queue, you always expect a complete item and if you don't it's corrupted data. Hence EOF errors do not make sense to pass up to the reader.

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.