-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
45 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,22 @@ | ||
import { deflate, inflate } from "pako"; | ||
import { concatBuffers } from "@ndn/util"; | ||
import { collect } from "streaming-iterables"; | ||
|
||
import type { PSyncCodec } from "./codec"; | ||
|
||
/** Use zlib compression with PSync. */ | ||
export const PSyncZlib: PSyncCodec.Compression = { | ||
compress(input) { | ||
return deflate(input, { level: 9 }); | ||
async compress(input) { | ||
return doTransform(input, new CompressionStream("deflate")); | ||
}, | ||
decompress(compressed) { | ||
return inflate(compressed); | ||
async decompress(compressed) { | ||
return doTransform(compressed, new DecompressionStream("deflate")); | ||
}, | ||
}; | ||
|
||
async function doTransform(input: Uint8Array, tr: TransformStream<Uint8Array, Uint8Array>): Promise<Uint8Array> { | ||
const chunks = await collect( | ||
new Blob([input]).stream() | ||
.pipeThrough(tr) as unknown as AsyncIterable<Uint8Array>, | ||
); | ||
return concatBuffers(chunks); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters