Documentation / @etherfold/processor-entities / readSnapshot
Function: readSnapshot() ​
readSnapshot(
document):Promise<SnapshotReader>
Defined in: packages/state-store/dist/snapshot-document.d.ts:253
Open a document: inflate it incrementally when it is gzipped, and read its head.
Whether to inflate is decided from the body's first two bytes, the gzip magic (1f 8b): a host that served the .gz opaque delivers them, and one that served it with Content-Encoding: gzip delivers the ndjson text, whose first line is JSON and so cannot begin with them. The bytes decide and not a header, for the reason a stream seed gives (streamSeedPayloadFrom, @etherfold/core): a browser that decoded transparently hides Content-Encoding from a script. Exactly ONE layer is peeled, so a body gzipped twice is refused. The bytes are PEEKED off the stream, never the body buffered, and cancelling the reader still cancels the underlying source.
Refuses with SnapshotFormatError when the head cannot be read as format 2 -- a gzipped body that does not inflate, a first line that is not JSON (a body gzipped twice, once inflated), or a format that is another number (format 1, which was plain JSON) -- because every one of those is a document this build cannot read, and none of them is a transport failure.
Parameters ​
document ​
Returns ​
Promise<SnapshotReader>