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

Function compress

packages/platform/node-shared/src/NodeHttpCompression.ts:46–77  ·  view source on GitHub ↗
(
  data: Uint8Array,
  algorithm: Platform.CompressionAlgorithm,
  options?: Platform.CompressionOptions | undefined
)

Source from the content-addressed store, hash-verified

44 level === undefined || level === 3 ? undefined : { params: { [Zlib.constants.ZSTD_c_compressionLevel]: level } }
45
46const compress = (
47 data: Uint8Array,
48 algorithm: Platform.CompressionAlgorithm,
49 options?: Platform.CompressionOptions | undefined
50): Effect.Effect<Uint8Array> =>
51 Effect.callback((resume) => {
52 const complete = (error: Error | null, result: Uint8Array) =>
53 resume(error === null ? Effect.succeed(result) : Effect.die(error))
54 switch (algorithm) {
55 case "gzip": {
56 Zlib.gzip(data, { level: options?.level }, complete)
57 break
58 }
59 case "deflate": {
60 Zlib.deflate(data, { level: options?.level }, complete)
61 break
62 }
63 case "br": {
64 Zlib.brotliCompress(data, brotliParams(options?.level, data.byteLength), complete)
65 break
66 }
67 case "zstd": {
68 const params = zstdParams(options?.level)
69 if (params === undefined) {
70 Zlib.zstdCompress(data, complete)
71 } else {
72 Zlib.zstdCompress(data, params, complete)
73 }
74 break
75 }
76 }
77 })
78
79/**
80 * Creates a `Compression` that compresses byte-array bodies in one shot with

Callers 1

compressResponseFunction · 0.85

Calls 2

brotliParamsFunction · 0.85
zstdParamsFunction · 0.85

Tested by

no test coverage detected