Compression Module

Types

Type Description

Algorithm

Functions and values

Function or value Description

MAX_BYTES_TO_COMPRESS

Full Usage: MAX_BYTES_TO_COMPRESS

Returns: int
Returns: int

MIN_BYTES_TO_COMPRESS

Full Usage: MIN_BYTES_TO_COMPRESS

Returns: int
Returns: int

compress encoding path fs

Full Usage: compress encoding path fs

Parameters:
Returns: Task<Result<unit, 'a>>
encoding : Algorithm
path : string
fs : Stream
Returns: Task<Result<unit, 'a>>

compressFile n stream compressionFolder

Full Usage: compressFile n stream compressionFolder

Parameters:
Returns: SocketOp<string>
n : Algorithm
stream : Stream
compressionFolder : string
Returns: SocketOp<string>

getEncoder request

Full Usage: getEncoder request

Parameters:
Returns: (Algorithm * (byte[] -> byte[])) option
request : HttpRequest
Returns: (Algorithm * (byte[] -> byte[])) option

loadEncoder s

Full Usage: loadEncoder s

Parameters:
    s : string

Returns: (Algorithm * (byte[] -> byte[])) option
s : string
Returns: (Algorithm * (byte[] -> byte[])) option

parseEncoder request

Full Usage: parseEncoder request

Parameters:
Returns: Algorithm option
request : HttpRequest
Returns: Algorithm option

transform content ctx

Full Usage: transform content ctx

Parameters:
Returns: Task<Algorithm option * byte[]>

Backwards-compatible task wrapper; new call sites should prefer `transformSync`.

content : byte[]
ctx : HttpContext
Returns: Task<Algorithm option * byte[]>

transformStream key stream getLast compression compressionFolder ctx

Full Usage: transformStream key stream getLast compression compressionFolder ctx

Parameters:
Returns: Task<Result<(Algorithm option * Stream), Error>>
key : string
stream : Stream
getLast : string -> DateTime
compression : bool
compressionFolder : string
ctx : HttpContext
Returns: Task<Result<(Algorithm option * Stream), Error>>

transformSync content ctx

Full Usage: transformSync content ctx

Parameters:
Returns: Algorithm option * byte[]
 Synchronous compression decision + transform.

 Hot-path-aware:
   1. If `content.Length` is outside the compressible range, returns immediately
      with no allocation and without inspecting any request headers.
   2. Otherwise checks for `accept-encoding`; if absent or unmatched, returns
      `(None, content)` without allocating a Task.
   3. Only when we are actually going to compress do we allocate the encoded
      byte array.

 This replaces the previous `task { }`-wrapped version that paid for a state
 machine + Task box + header lookup + comma-split + Array.map/tryPick on
 every `Bytes` response, even when no compression was possible.
content : byte[]
ctx : HttpContext
Returns: Algorithm option * byte[]