MCPcopy Create free account
hub / github.com/Effect-TS/effect / deflateBytes

Function deflateBytes

packages/effect/src/encoding/Zip.ts:700–716  ·  view source on GitHub ↗
(bytes: Uint8Array)

Source from the content-addressed store, hash-verified

698
699// One promise per in-memory entry costs less than a stream
700const deflateBytes = async (bytes: Uint8Array): Promise<Uint8Array> => {
701 const compressor = new CompressionStream("deflate-raw")
702 const writer = compressor.writable.getWriter()
703 // A failed write errors the readable, so the reads report it
704 if (bytes.length > 0) writer.write(compressible(bytes)).catch(() => {})
705 writer.close().catch(() => {})
706 const reader = compressor.readable.getReader()
707 const chunks: Array<Uint8Array> = []
708 let length = 0
709 while (true) {
710 const { done, value } = await reader.read()
711 if (done) break
712 chunks.push(value)
713 length += value.length
714 }
715 return concat(chunks, length)
716}
717
718const concat = (chunks: ReadonlyArray<Uint8Array>, length: number): Uint8Array => {
719 if (chunks.length === 1) return chunks[0]

Callers 2

startDeflatesFunction · 0.85
encodeFunction · 0.85

Calls 6

compressibleFunction · 0.85
concatFunction · 0.70
writeMethod · 0.65
closeMethod · 0.65
readMethod · 0.65
pushMethod · 0.65

Tested by

no test coverage detected