zztaeha

TypeScriptMIT

Deflate, zlib, gzip and zip for every JavaScript runtime.

kokyu compresses and decompresses raw deflate, zlib, gzip and zip, in TypeScript with no dependencies at all. The same code runs in Node, Deno, Bun and the browser, and every format comes four ways: a one-shot call, an async call that runs large inputs in a pool of workers off the main thread, a stream that takes its input in chunks, and an async stream that does both.

Input you didn't make is treated as hostile. Every decoder takes a cap on its output, and zip names that an extractor would write somewhere else are refused when you write them. Every error kokyu raises itself is a KokyuError, with a code to branch on.


Start here

  1. Try it in your browser: a sample or your own files, compressed and timed.
  2. Install it: one package, no setup.
  3. Compress and decompress in one call, as a stream or off the main thread, and read and write zip archives.
  4. Look something up among the 73 documented names, every function and type with an example.

The source is at github.com/zztaeha/kokyu.

What holds it up

  • No dependencies, so what you install is kokyu and nothing else.
  • Its tests check deflate, zlib and gzip against node:zlib, fuzz all four formats with seeded random data, sizes, levels and chunkings, and throw hostile archives built byte by byte at the zip reader.
  • Its security and bug review ran in passes until a whole pass of the library found nothing.
  • Checks of every API family run unchanged in Node, Bun, Deno, Chrome and Safari.

What it supports

FormatsRaw deflate (RFC 1951), zlib (RFC 1950) with preset dictionaries, gzip (RFC 1952) with its file name and time, and files of several gzip members.
ZipStored and deflated entries, written from an object of paths or entry by entry. Read whole, listed without decompressing, or as a stream from the front. ZIP64, data descriptors, Unix modes, entry comments and names that aren't UTF-8 are read.
Four waysOne-shot calls, streams, async calls run in a worker pool, and async streams, for every format. Any stream becomes a web TransformStream.
LimitsA cap on output for every decoder, decoding straight into a buffer you own, and async calls that copy their input as they're made, so a buffer reused right after can't change the result.
RuntimesNode, Deno, Bun, and browsers. Workers are Node's own threads in Node and module workers everywhere else.
AndCRC-32 and Adler-32, and text to UTF-8 or latin1 bytes and back.

Installing

npm install kokyu

kokyu has no dependencies, so that is all there is to fetch. It is an ES module: import what you use by name. In Deno, import it from npm:kokyu.

import { gzip, gunzip, encodeText, decodeText } from 'kokyu'

const packed = gzip(encodeText('hello, kokyu'))
decodeText(gunzip(packed)) // 'hello, kokyu'

What it adds to a bundle

The package declares no side effects, so a bundler keeps only what you import. Minified with Bun for the browser, the common cuts come to:

What you importMinifiedGzipped
Decompression only (inflate)6.6 KB3.3 KB
Compression only (deflate)7.7 KB3.9 KB
Both12.5 KB6.2 KB
Everything, zip and the async API included52.4 KB21.5 KB

Workers and bundlers

The async API runs large inputs in workers, which start on the first such call. kokyu finds its worker file as new URL('./worker.js', import.meta.url), the form bundlers recognize, so a bundler that follows it ships the worker beside your code with nothing to configure. The one-shot calls and the streams never start a worker.

In Node, workers are Node's own worker threads. Everywhere else they are module workers. A worker keeps the time zone it started with, and zip entries store local time, so set TZ before the first async call if you set it at all.

Runtimes

The same build runs in Node, Deno, Bun and browsers, with nothing to polyfill. Checks of every API family run unchanged in Node, Deno, Bun, Chrome and Safari.

TypeScript

kokyu is written in TypeScript and ships its declarations. It needs TypeScript 5.7 or newer, the first to make Uint8Array generic over its buffer. TypeScript 5.6 rejects kokyu's declarations for that reason.

Outputs are typed Uint8Array<ArrayBuffer>

Since 5.7, a plain Uint8Array may sit on shared memory, and Blob, Response, fetch bodies and crypto.subtle refuse one for that reason. Every array kokyu returns sits on an ArrayBuffer of its own and is typed that way, so it goes straight into any of them, with no cast.

import { gzip, encodeText } from 'kokyu'

const packed = gzip(encodeText('report'))
const file = new Blob([packed], { type: 'application/gzip' })
const digest = await crypto.subtle.digest('SHA-256', packed)

Inputs can be any Uint8Array

Every input is typed plain Uint8Array: a Node Buffer, a view of part of a buffer, a view of shared or resizable memory, or one from another realm all go in as they are. Anything else, an ArrayBuffer or a Uint16Array say, is refused with invalid-option rather than read as the wrong bytes.

Decoding into your own buffer keeps its type

The …Into decoders write into the buffer you hand them and return the view of it that holds the output, typed after it: a view of shared memory comes back as Uint8Array<SharedArrayBuffer>.

import { deflate, inflateInto } from 'kokyu'

const shared = new Uint8Array(new SharedArrayBuffer(1024))
const view: Uint8Array<SharedArrayBuffer> = inflateInto(deflate(new Uint8Array(100).fill(7)), shared)
view.length // 100, at the start of shared

Options and errors

Every options type is exported, and every field accepts undefined as well as being left out, so options built under exactOptionalPropertyTypes pass as they are. A caught error narrows with instanceof KokyuError, and its code is a union of string literals, so a switch over it can be checked for exhaustiveness.

import { inflate, deflate, KokyuError } from 'kokyu'
import type { InflateOptions } from 'kokyu'

const opts: InflateOptions = { maxSize: 1000, dictionary: undefined }
try {
  inflate(deflate(new Uint8Array(5000)), opts)
} catch (e) {
  if (e instanceof KokyuError && e.code === 'too-large') console.log('more than 1000 bytes')
}

Compressing and decompressing

Each format has a pair of calls, one each way, that take the whole input and return the whole output. Bytes go in and come out as Uint8Arrays; encodeText and decodeText cross to and from strings.

FormatCompressDecompressWhat it is
Raw deflatedeflateinflateThe compressed data alone (RFC 1951), for formats that frame it themselves.
zlibzlibunzlibDeflate in a 2-byte header and an Adler-32 trailer (RFC 1950), as PNG and many protocols carry it.
gzipgzipgunzipDeflate with a header that can name the file, and a CRC-32 and length trailer (RFC 1952): .gz files and HTTP's gzip encoding.
Any of the threedecompressReads gzip or zlib by its header, and anything else as raw deflate, so bytes in none of the three can still decode, to garbage.
import { gzip, gunzip, decompress, encodeText, decodeText } from 'kokyu'

const packed = gzip(encodeText('to be or not to be, '.repeat(100)))
packed.length // 53 bytes, from 2,000
decodeText(gunzip(packed)).length // 2000
decodeText(decompress(packed)).length // 2000, found to be gzip by its header

Levels

Every compressor takes a level from 0 to 9: 1 is fastest, 9 searches hardest, and 6, the default, sits between. A higher level usually means smaller output, though not on every input: now and then a lower one comes out a few bytes smaller. Level 0 stores the data without compressing it, in blocks any decoder reads. Any other value fails with invalid-option rather than being rounded into range.

Output is the same bytes for the same input, level and dictionary, every time and in every runtime. gzip's header holds no time unless you give it one in mtime, so a .gz file is reproducible too.

Dictionaries

Short inputs that share their opening, such as messages of one protocol, compress far better against a preset dictionary of the bytes they tend to repeat. The decoder needs the same bytes. zlib records which dictionary it was made with, so unzlib refuses a missing or wrong one with invalid-option. Raw deflate records nothing: without the dictionary, data that refers back into it fails, and with the wrong one it decodes to the wrong bytes. gzip has no dictionaries.

import { zlib, unzlib, encodeText, decodeText } from 'kokyu'

const dictionary = encodeText('the quick brown fox jumps over the lazy dog')
const message = encodeText('the lazy dog and the quick brown fox')
zlib(message).length // 42
const packed = zlib(message, { dictionary }) // 21 bytes
decodeText(unzlib(packed, { dictionary })) // 'the lazy dog and the quick brown fox'

Capping the output

A few kilobytes of deflate data can decode to gigabytes. Every decoder takes a maxSize in bytes and fails with too-large as soon as its output would pass it. There is no cap unless you set one, so set one for input you didn't make.

import { deflate, inflate, KokyuError } from 'kokyu'

const bomb = deflate(new Uint8Array(50_000_000)) // 50 MB of zeros in 50,817 bytes
try {
  inflate(bomb, { maxSize: 10_000_000 })
} catch (e) {
  if (e instanceof KokyuError) e.code // 'too-large'
}

Decoding into a buffer you already have

inflateInto, unzlibInto, gunzipInto and decompressInto write the output into a Uint8Array you hand them, allocating nothing for it, and return the view of it that holds the output. Output that doesn't fit fails with too-large, so the buffer's size is a cap of its own; after that failure the buffer may already hold part of the output. A maxSize still applies, and the smaller of the two wins.

import { gzip, gunzipInto, encodeText } from 'kokyu'

const buffer = new Uint8Array(64 * 1024)
const view = gunzipInto(gzip(encodeText('hello')), buffer)
view.length // 5, the start of buffer

Checksums aren't checked

The decoders don't compare the CRC-32 or Adler-32 a stream carries, gzip's optional header CRC included. What they still check costs nothing: data that ends before its trailer fails with truncated, and a gzip length or a zip entry size that disagrees with the data fails with invalid-data. Every compressor writes every checksum. To verify one, run crc32 or adler32 over the output and compare.

import { gzip, gunzip, crc32, encodeText } from 'kokyu'

const gz = gzip(encodeText('checked by you'))
const text = gunzip(gz)
const stored = new DataView(gz.buffer).getUint32(gz.length - 8, true)
crc32(text) === stored // true

Multi-member gzip

A gzip file can hold several members one after another, as cat a.gz b.gz makes. gunzip and gunzipStream read every member and return their contents joined. Bytes after the last member are ignored, as gzip itself ignores them, unless they start another member: one that stops short fails with truncated.

import { gzip, gunzip, encodeText, decodeText } from 'kokyu'

const a = gzip(encodeText('first, ')), b = gzip(encodeText('second'))
const both = new Uint8Array([...a, ...b])
decodeText(gunzip(both)) // 'first, second'

Streams

For input that arrives in pieces, or output too big to hold at once, every format has a stream: deflateStream, inflateStream, zlibStream, unzlibStream, gzipStream, gunzipStream, decompressStream, and zip's own zipStream and unzipStream. Each takes the same options as its one-shot call, read when the stream is made.

A stream has two calls. push adds a chunk and returns the output that chunk completes, which may be empty while the coder gathers enough to write a block. finish adds an optional last chunk and returns the rest. Chunks can be any size. Joined, a decoder's outputs are exactly what its one-shot call returns, and so are a compressor's at levels 1 to 9 if you never flush; at level 0 they may end in one more empty block.

import { deflateStream, inflate, encodeText } from 'kokyu'

const text = encodeText('stream me '.repeat(10_000))
const s = deflateStream()
const parts = [
  s.push(text.subarray(0, 50_000)), // 0 bytes: nothing complete yet
  s.push(text.subarray(50_000)), // 0 bytes
  s.finish(), // 222 bytes: everything
]

Flushing

A compressor's stream also has flush, which returns everything pushed so far as output a decoder can read in full, without ending the stream: for a message protocol that sends each message as it's written. Each flush costs a few bytes, so flush only where the other side must read up to that point.

import { gzipStream, gunzipStream, encodeText, decodeText } from 'kokyu'

const writer = gzipStream(), reader = gunzipStream()
// Everything the writer returns goes to the reader: this first push returns the gzip header
reader.push(writer.push(encodeText('first message'))) // nothing to read yet
decodeText(reader.push(writer.flush())) // 'first message', while both streams stay open

After a finish, and after a failure

A finished stream refuses every later call with invalid-state, and lets go of its buffers and tables at once, even while you still hold it. A decoder that fails partway can't tell where the data would go on, so every later call throws the same error again rather than decode past it. A chunk refused before any work starts, one that isn't a Uint8Array say, leaves the stream as it was, and a good chunk can follow.

import { gunzipStream, gzip, encodeText, KokyuError } from 'kokyu'

const s = gunzipStream()
try { s.push('not bytes' as never) } catch (e) { (e as KokyuError).code } // 'invalid-option'
s.finish(gzip(encodeText('fine'))) // still works: 4 bytes

A stream is called one call at a time. A call made from inside another of the same stream's calls, from a getter on its options or a zip filter say, is refused with invalid-state.

Web streams

toTransformStream wraps any kokyu stream, sync or async, as a web TransformStream, so it slots into pipeThrough with files, fetch bodies and sockets. Decoders that return arrays, like unzipStream, enqueue each element on its own.

import { gzipStream, gunzip, toTransformStream, encodeText } from 'kokyu'

const text = encodeText('piped through '.repeat(10_000))
const gzipped = new Blob([text]).stream().pipeThrough(toTransformStream(gzipStream()))
const bytes = new Uint8Array(await new Response(gzipped).arrayBuffer())

A pipe that fails midway still finishes the stream it wraps, so an async stream's worker session closes rather than linger, and so does a canceled one, in runtimes that call a transformer's cancel. The one exception is a zip entry's stream, which stays open: finishing it would write a cut-off entry into an archive you may go on with. If a cancel could have thrown away bytes the entry had returned, the archive refuses to finish. Bytes the pipe has already handed on are out of its sight, so don't finish an archive whose output pipe was aborted.

Async

Compressing megabytes on the main thread holds up everything else on it. Every one-shot call and every stream has an async twin that returns promises and does the work in a worker: deflateAsync, gunzipAsync, zipAsync, unzipStreamAsync and the rest, 18 in all. Each takes the same options as its sync twin, plus a signal and transfer.

import { gzipAsync, gunzip, encodeText } from 'kokyu'

const text = encodeText('kokyu '.repeat(200_000)) // 1.2 MB
const packed = await gzipAsync(text) // compressed in a worker: 1,840 bytes

What runs where

A one-shot input under 16 KB runs on the calling thread, where a round trip to a worker would cost more than the work. Anything larger goes to a pool of workers, which start on the first such call and are reused after. The pool holds up to one worker fewer than the machine has cores, at least one and at most four. The line is drawn on the input, so a small input that decodes to a lot still runs on the calling thread, and maxSize is what caps it.

An async stream runs on the calling thread only when the whole stream is under 16 KB and finished within one tick: opened, pushed and finished without an await in between. unzipStreamAsync with a filter stays only when its first call is a finish that holds the whole archive. Anything else opens a session in one worker, which keeps the stream's state until it finishes or fails.

The pool never keeps a Node process alive while it's idle, so a script that's done exits. In Deno, where a worker can't be told not to hold the process, an idle worker with no open stream retires after half a second, but one holding an unfinished stream keeps the process running: finish or abort every stream you open.

Calls in order, without waiting

A stream's calls can be made without awaiting each one. They go to the worker in the order they were made and settle in that order, so the results can be written out as they come.

import { deflateStreamAsync, inflate, encodeText } from 'kokyu'

const text = encodeText('kokyu '.repeat(200_000))
const s = deflateStreamAsync()
const calls = [s.push(text.subarray(0, 600_000)), s.push(text.subarray(600_000)), s.finish()]
const parts = await Promise.all(calls)

Copies, and transfer

An async call copies its input as it's made, so reusing the buffer as soon as the call returns, as a read loop does, can't change the result. Options are read at the call too.

With transfer: true, an input that goes to a worker moves there instead of being copied, which empties your array. Only an input that covers its whole ArrayBuffer can move. An input small enough to run on the calling thread, or a view of part of a larger buffer, is copied as usual. For zipAsync the entries' total decides, and then every entry that covers its whole buffer moves, small ones too.

import { gzipAsync } from 'kokyu'

const data = new Uint8Array(1 << 20).fill(1)
const done = gzipAsync(data, { transfer: true })
data.length // 0: the buffer is the worker's now
await done

Canceling

An AbortSignal in signal cancels a call, or a whole stream: every one of its promises not yet settled rejects with the signal's reason. A job still waiting for a worker never starts. One already running is stopped by retiring its worker when nothing else is in that worker, and otherwise finishes unseen. Once a call has started, an abort that lands before its promise settles rejects it with the reason, whatever it would have settled with.

import { gzipAsync } from 'kokyu'

const controller = new AbortController()
const call = gzipAsync(new Uint8Array(1 << 20), { signal: controller.signal })
controller.abort(new Error('user canceled'))
await call.catch((e: Error) => e.message) // 'user canceled'

Failures

Every failure comes back through the promise, a bad argument included: an async call never throws as you make it. Its error is the one the sync call would throw, a KokyuError with its code. A worker that fails to start or dies rejects its calls with the code worker. A call made with a signal that's already aborted rejects with its reason, though some bad arguments are refused before the signal is looked at.

Callbacks run on your thread

unzipAsync and unzipStreamAsync call their filter on the calling thread, since a function can't be sent to a worker; with unzipStreamAsync, the worker waits at each entry for the filter's answer. A zip entry without an mtime is stamped with the time of the call, not the time a worker gets to it. A worker keeps the time zone it started with, so in Node set TZ before the first async call.

Zip

A zip archive is written from a plain object that maps paths to bytes, and read back as one. A value can also be [bytes, options] for one entry's own options, or another object for a folder, whose paths join with /. An empty folder becomes a directory entry.

import { zip, unzip, encodeText } from 'kokyu'

const archive = zip({
  'readme.txt': encodeText('hello'),
  src: {
    'main.ts': encodeText('export {}'),
    'run.sh': [encodeText('#!/bin/sh'), { mode: 0o755 }],
  },
  empty: {},
})
Object.keys(unzip(archive)) // ['readme.txt', 'src/main.ts', 'src/run.sh', 'empty/']

What each entry gets

Each entry is deflated at the archive's level, 6 unless set, and stored instead wherever deflate can't make it smaller. Entries are marked as made on Unix, with mode 0o644 for a file and 0o755 for a folder, as Python and Info-ZIP write them on Unix; mode sets other permission bits. Times are local, to the 2 seconds zip keeps, from 1980 to 2107; without an mtime, an entry gets the time it was written.

Names that extractors would write somewhere other than where they say are refused with invalid-option: an empty name, one with a \ or a control character, one that starts with / or a drive letter or holds an empty, . or .. folder, a file name ending in ;, with or without digits after it, and two names for one path, such as a file and a folder of the same name. Each of them extracts to another path in at least one of Info-ZIP, bsdtar or Python's zipfile.

import { zip, encodeText, KokyuError } from 'kokyu'

try {
  zip({ '../evil.sh': encodeText('#!/bin/sh') })
} catch (e) {
  (e as KokyuError).code // 'invalid-option'
}

kokyu writes no ZIP64, so an archive past 4 GB or 65,534 entries fails with too-large. An archive comment holds at most 16,361 bytes, since bsdtar looks for an archive's end only in its last 16 KB.

Reading

unzip returns an object of paths and their bytes, directories with empty data. A filter sees each entry as the central directory lists it, sizes, time, comment and Unix mode included, and an entry it turns down is never decompressed. A maxSize caps all the entries kept, taken together. zipEntries lists the entries without decompressing any.

import { zip, unzip, zipEntries, encodeText } from 'kokyu'

const archive = zip({ 'a.ts': encodeText('export {}'), 'notes.md': encodeText('# notes') })
Object.keys(unzip(archive, { filter: (e) => e.name.endsWith('.ts'), maxSize: 10_000_000 })) // ['a.ts']
zipEntries(archive).map((e) => [e.name, e.originalSize]) // [['a.ts', 9], ['notes.md', 7]]

The readers take ZIP64, data descriptors, entry comments and Unix modes. The archive's own comment is written but not returned. A name the archive doesn't mark as UTF-8 is read as UTF-8 if it is valid UTF-8, and otherwise as code page 437, the encoding the zip specification gives such names. unzip refuses entries that share their bytes, as an overlapping zip bomb's do, with invalid-data, and an encrypted entry with unsupported unless its filter turns the entry down.

The name rules hold for what kokyu writes, not for what it reads: an entry name comes back exactly as the archive stores it, ../ and all. Check a name before you use it as a path.

As streams

zipStream writes an archive one entry at a time, for data you don't hold all at once: file starts an entry and returns its stream, which you push to and finish before the next. Each call returns the archive bytes it completes, so they can go straight out. An entry's sizes and CRC-32 follow its data in a data descriptor, and level 0 stores the data in deflate's own stored blocks, which mark where they end, so an entry can be read safely as a stream too.

import { zipStream, unzip, encodeText, decodeText } from 'kokyu'

const z = zipStream()
const log = z.file('log.txt')
const parts = [log.push(encodeText('line 1\n')), log.push(encodeText('line 2\n')), log.finish(), z.finish()]
const archive = new Uint8Array(parts.flatMap((p) => [...p]))
decodeText(unzip(archive)['log.txt']!) // 'line 1\nline 2\n'

unzipStream reads an archive from the front as its bytes arrive, without needing the end of it first. Each call returns the pieces of entries it completes, each with the entry it belongs to: the same object for every piece of one entry, so it can key a Map, and final on its last. Where an entry's sizes follow its data, the stream doesn't know them when the entry starts, so size and originalSize are left out rather than given as zero.

import { zip, unzipStream, encodeText } from 'kokyu'

const archive = zip({ 'a.txt': encodeText('first'), 'b.txt': encodeText('second') })
const reader = unzipStream()
const pieces = []
for (let at = 0; at < archive.length; at += 50) pieces.push(...reader.push(archive.subarray(at, at + 50)))
pieces.push(...reader.finish())
pieces.filter((p) => p.final).map((p) => p.entry.name) // ['a.txt', 'b.txt']

Text and checksums

Text

Compression works on bytes, so text crosses over with encodeText and back with decodeText. Both use UTF-8 unless you ask for latin1, one byte per character, which holds only U+0000 to U+00FF; a character past that fails with invalid-option rather than turning into another. Decoding UTF-8 that isn't valid puts U+FFFD where the bad bytes were, as TextDecoder does.

import { encodeText, decodeText } from 'kokyu'

encodeText('héllo').length // 6: é takes two bytes in UTF-8
encodeText('héllo', { latin1: true }).length // 5
decodeText(new Uint8Array([0x61, 0xFF, 0x62])) // 'a\uFFFDb'

encodeTextStream and decodeTextStream do the same in pieces, and keep a character whole when a chunk ends in the middle of it: a UTF-8 sequence cut between two chunks, or a surrogate pair split between two strings, comes out once, from the call that completes it.

import { encodeText, decodeTextStream } from 'kokyu'

const bytes = encodeText('é🎉') // 2 bytes, then 4
const s = decodeTextStream()
const out = [s.push(bytes.subarray(0, 1)), s.push(bytes.subarray(1, 3)), s.push(bytes.subarray(3))]
out.push(s.finish())
// ['', 'é', '🎉', '']

Checksums

crc32 is the checksum gzip and zip store, and adler32 the one zlib stores. Each returns a whole number from 0 to 2³² − 1, and continues over more data when you hand it its previous result, so a checksum over data that arrives in pieces needs no buffer. The decoders don't check the checksums they read; these are how you check one yourself.

import { crc32, encodeText } from 'kokyu'

let crc = 0
for (const piece of ['1234', '56789']) crc = crc32(encodeText(piece), crc)
crc === 0xCBF43926 // true: the CRC-32 of '123456789'

Errors and untrusted input

Every error kokyu raises itself is a KokyuError: an Error whose code says what went wrong and stays the same across versions, and whose message is for people and may change. Branch on the code. Two kinds of error pass through as they are: an abort rejects with its signal's reason, and an exception your own filter throws is rethrown unchanged.

CodeWhat went wrong
truncatedThe data ends before it should.
invalid-dataThe data is corrupt, or a stated size doesn't match it.
invalid-headerA zlib or gzip header is wrong: not that format at all, more often than not.
too-largeThe output would pass maxSize, the buffer given to an …Into call, or a zip entry's stated size, or an archive being written needs ZIP64.
unsupportedThe data uses something kokyu doesn't read, such as a zip entry's encryption.
invalid-optionAn argument or option is wrong: bytes that aren't a Uint8Array, a level out of range, a zip name that would extract elsewhere. Also zlib data whose preset dictionary is missing or wrong.
invalid-stateA stream was used after it finished, from inside one of its own calls, or out of order.
workerA worker of the async pool failed to start or died.
import { gunzip, encodeText, KokyuError } from 'kokyu'

try {
  gunzip(encodeText('not gzip at all'))
} catch (e) {
  if (!(e instanceof KokyuError)) throw e
  e.code // 'invalid-header'
  e.message // 'kokyu: not a gzip stream'
}

Input you didn't make

  • Cap every decode. No decoder has a limit on its output unless you give it a maxSize, and a small input can decode to gigabytes. For a zip archive, maxSize caps all the entries kept, taken together.
  • Check what matters yourself. Decoders don't verify checksums, so corrupt data whose structure still parses decodes to wrong bytes without an error. Where that matters, compare a crc32 of the output.
  • Names in messages are quoted. A message that names a zip entry puts the name in quotes with every control, line break and bidi character escaped, so a name can't forge a line in your logs. A value you passed shows only by its type, as in "got string".
  • Entry names are the archive's. unzip and unzipStream return each name exactly as stored, ../ and absolute paths included. Check a name before you join it to a folder.
  • Hostile archives are refused. unzip refuses entries that share bytes, a size no deflate data could reach, and archives split across files, and fails an entry whose data runs short of what it claims.

When your code runs inside a call

Some of what you hand kokyu is code: a getter or a Proxy on an options object, an object's toString or valueOf, a zip filter. kokyu runs it in the middle of a call, and it may do anything, including calling kokyu again or changing the input it was given. Whatever it does, kokyu holds to four things:

  1. No call hangs.
  2. No error escapes but a KokyuError, your own code's throw, or an abort's reason.
  3. No output is silently wrong.
  4. Every limit documented here holds.

What isn't promised is that such code meets the same outcome in a sync call and its async twin: which of two refusals comes first, how often a getter is read, or the words of a refusal. A stream called from your code while one of its own calls is under way refuses that inner call with invalid-state.

One thing is outside all of this: a typed array whose built-in properties, such as length or buffer, are redefined, on the array or in a subclass, to report anything other than the array, or to detach or resize its buffer as they're read. That is a forgery, not an input, and nothing above holds for it. A subclass whose getters only pass through is an ordinary input.

Reference

73 names: everything kokyu 0.1.0 makes public. Each entry says what the thing does, what comes back and what it fails with, and shows an example that was type-checked and run against 0.1.0.

The lists come from kokyu's compiled declarations, as the compiler exports them, so no name is transcribed by hand and none is left out. Each signature is the one your editor shows. Both lists are filed under the same areas.

SectionNames
Functions48
Types25

Press / or ⌘K to search all of them by name, fields and methods included. A name in an entry's text that is itself an entry links to it.

Loading Functions…

Loading Types…

Type to search.