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

Function deflate

packages/effect/src/encoding/Zip.ts:660–682  ·  view source on GitHub ↗
(input: Stream.Stream<Uint8Array, E, R>)

Source from the content-addressed store, hash-verified

658
659// Compressor failures, including a runtime without `deflate-raw`, are defects
660const deflate = <E, R>(input: Stream.Stream<Uint8Array, E, R>): Stream.Stream<Uint8Array, E, R> =>
661 Stream.unwrap(Effect.map(
662 Effect.sync(() => new CompressionStream("deflate-raw")),
663 (compressor) => {
664 const writer = compressor.writable.getWriter()
665 const feed = Stream.runForEach(
666 input,
667 (chunk) => Effect.promise(() => writer.write(compressible(chunk)))
668 ).pipe(
669 Effect.andThen(Effect.promise(() => writer.close())),
670 Effect.onError(() =>
671 Effect.sync(() => {
672 writer.abort().catch(() => {})
673 })
674 )
675 )
676 const output = Stream.orDie(Stream.fromReadableStream({
677 evaluate: () => compressor.readable,
678 onError: (cause) => cause
679 }))
680 return Stream.merge(output, Stream.fromEffectDrain(feed))
681 }
682 ))
683
684// CompressionStream rejects views of a SharedArrayBuffer
685const compressible = (bytes: Uint8Array): Uint8Array<ArrayBuffer> =>

Callers 1

encodeFunction · 0.85

Calls 9

compressibleFunction · 0.85
onErrorMethod · 0.80
pipeMethod · 0.65
writeMethod · 0.65
closeMethod · 0.65
abortMethod · 0.65
mergeMethod · 0.65
mapMethod · 0.45
syncMethod · 0.45

Tested by

no test coverage detected