compress
compress(
data,options):Promise<Uint8Array<ArrayBuffer>>
Defined in: next/api.d.ts:304
Compress data in options.format.
The output holds the same bytes as that of the functions of the root
entry at the same settings, such as zstdCompress(data, level), or
deflateCompress(data, level) for 'deflate-raw', unless zstd compresses
with workers, or with a Dictionary above level 8, or with a
Dictionary an input of more than 512 KiB or of at least 128 KiB and at
least 6 times the Dictionary.byteLength of the dictionary. zstd
compresses an input of at least 128 KiB and 6 times the size of the
dictionary with parameters for its size rather than those that the
Dictionary was prepared for, and above level 8 or 512 KiB, it sizes its
window or splits blocks otherwise with a Dictionary than with its bytes.
The bytes of the dictionary decompress the output either way.
The data and the bytes of a dictionary are copied when compress() is called, so changing them afterwards does not change the result, and the call keeps using a Dictionary that is closed afterwards. In Node.js, the data is compressed on a thread of the libuv pool. The browser build has no such pool: it compresses the data on the calling thread, which it blocks, before compress() returns.
An AbortOptions.signal withdraws the call.
Parameters
Section titled “Parameters”options
Section titled “options”CompressOptions<Format> & AbortOptions
Returns
Section titled “Returns”Promise<Uint8Array<ArrayBuffer>>
A Promise of the compressed data, which rejects on every error,
invalid arguments included, with an ErrorCode as code, or with
the reason of the signal once it aborts. compress() itself never throws.