import type { FilesPlugin } from "../index.js"; /** * Compression algorithm for {@link compression}, matching the formats the * platform {@link CompressionStream} supports. `"gzip"` (the default) carries a * small header/footer and a checksum; `"deflate"` is zlib-wrapped raw deflate; * `"deflate-raw"` is the bare deflate stream with no framing. Brotli is * deliberately absent — it isn't part of the Compression Streams standard, so * supporting it would mean a native dependency and break isomorphism. */ export type CompressionFormat = "gzip" | "deflate" | "deflate-raw"; export interface CompressionOptions { /** * Which algorithm to compress new uploads with. Defaults to `"gzip"`. The * algorithm used for a given object is recorded in its metadata, so reads * always decompress with the right one — changing this option never breaks * objects written under the old format. */ format?: CompressionFormat; } /** * Transparently compress object bodies at rest. On `upload` the body is * compressed (gzip by default) and the original byte length plus the algorithm * ride along in the object's `metadata`; on `download` it's decompressed back to * the original bytes — for `upload([...])` / `download([...])` bulk calls too. * If compressing wouldn't shrink an object (already-compressed data like * JPEG/ZIP/encrypted blobs), the original bytes are stored verbatim, so the * plugin never inflates your storage. * * Provider-agnostic: it uses only the platform {@link CompressionStream} (no * native deps) and the `metadata` the SDK already round-trips, so it works on * any adapter that supports metadata. * * Place it **before** `encryption()` in the plugin array — compression must see * plaintext, since encrypted bytes don't compress: `plugins: [compression(), * encryption(key)]`. Reads unwind the onion in reverse automatically (decrypt → * decompress). * * Trade-offs, by design: * - **Buffers the whole body** to compare compressed vs original size, so it's * unsuitable for unknown-length streams and resumable uploads. * - **Range downloads throw** — a byte range of the original maps to no fixed * slice of the compressed bytes. * - **`url()` / `signedUploadUrl()` throw** — a presigned GET hands out * compressed bytes with no `Content-Encoding`, which clients can't read, and a * presigned PUT would silently bypass compression. * - **`copy` / `move` just work** — the algorithm marker travels with the object. * - Objects without this plugin's marker (pre-existing or written elsewhere) * **pass through** on read, so it's safe to enable on a mixed bucket. * * @param options optional `{ format }` — `"gzip"` (default), `"deflate"`, or * `"deflate-raw"`. * @example * ```ts * import { createFiles } from "files-sdk"; * import { s3 } from "files-sdk/s3"; * import { compression } from "files-sdk/compression"; * * const files = createFiles({ * adapter: s3({ bucket: "uploads" }), * plugins: [compression()], * }); * * await files.upload("notes.txt", "a".repeat(10_000)); // stored gzipped * await (await files.download("notes.txt")).text(); // the original 10k string * ``` */ export declare const compression: (options?: CompressionOptions) => FilesPlugin; //# sourceMappingURL=index.d.ts.map