Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/zipjs/index.js>ZipWriterStream

JavaScript library to zip and unzip files supporting multi-core compression, compression streams, zip64, split files and encryption.
Latest
class ZipWriterStream
import { ZipWriterStream } from "https://deno.land/x/zipjs@v2.7.53/index.js";

Represents an instance used to create a zipped stream.

Examples

This example creates a zipped file called numbers.txt.zip containing the numbers 0 - 1000 each on their own line.

const readable = ReadableStream.from((function* () {
  for (let i = 0; i < 1000; ++i)
    yield i + '\n'
})())

readable
  .pipeThrough(new ZipWriterStream().transform('numbers.txt'))
  .pipeTo((await Deno.create('numbers.txt.zip')).writable)

This example creates a zipped file called Archive.zip containing two files called numbers.txt and letters.txt

const readable1 = ReadableStream.from((function* () {
  for (let i = 0; i < 1000; ++i)
    yield i + '\n'
})())
const readable2 = ReadableStream.from((function* () {
  const letters = 'abcdefghijklmnopqrstuvwxyz'.split('')
  while (letters.length)
    yield letters.shift() + '\n'
})())

const zipper = new ZipWriterStream()
zipper.readable.pipeTo((await Deno.create('Archive.zip')).writable)
readable1.pipeTo(zipper.writable('numbers.txt'))
readable2.pipeTo(zipper.writable('letters.txt'))
zipper.close()

Constructors

new
ZipWriterStream(options?: ZipWriterConstructorOptions)

Creates the stream.

Properties

readable: ReadableStream<Uint8Array>

The readable stream.

zipWriter: ZipWriter<unknown>

The ZipWriter property.

Methods

close(comment?: Uint8Array, options?: ZipWriterCloseOptions): Promise<unknown>

Writes the entries directory, writes the global comment, and returns the content of the zipped file.

transform<T>(path: string): { readable: ReadableStream<T>; writable: WritableStream<T>; }

Returns an object containing a readable and writable property for the .pipeThrough method

writable<T>(path: string): WritableStream<T>

Returns a WritableStream for the .pipeTo method