Skip to content

Commit a12c1f5

Browse files
Merge pull request #510 from jespertheend/zipreaderstream-example
fix ZipReaderStream example
2 parents 1cb7354 + b41e1c2 commit a12c1f5

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

Diff for: index.d.ts

+13-7
Original file line numberDiff line numberDiff line change
@@ -629,15 +629,21 @@ export class Uint8ArrayWriter extends Writer<Uint8Array> { }
629629
* Represents an instance used to create an unzipped stream.
630630
*
631631
* @example
632-
* This example will take a zip file, decompress it and then recompress each file in it, saving it to disk.
632+
* This example will take a zip file, decompress it and then save its files and directories to disk.
633633
* ```
634-
* for await (const entry of (await fetch(urlToZippedFile)).body.pipeThrough(new ZipWriterStream()))
635-
* if (entry.readable) {
636-
* console.log(entry.filename)
637-
* entry.readable
638-
* .pipeThrough(ZipReaderStream().transform(entry.filename))
639-
* .pipeTo((await Deno.create(entry.filename + '.zip')).writable)
634+
* import {resolve} from "https://deno.land/std/path/mod.ts";
635+
* import {ensureDir, ensureFile} from "https://deno.land/std/fs/mod.ts";
636+
*
637+
* for await (const entry of (await fetch(urlToZippedFile)).body.pipeThrough(new ZipReaderStream())) {
638+
* const fullPath = resolve(destination, entry.filename);
639+
* if (entry.directory) {
640+
* await ensureDir(fullPath);
641+
* continue;
640642
* }
643+
*
644+
* await ensureFile(fullPath);
645+
* await entry.readable?.pipeTo((await Deno.create(fullPath)).writable);
646+
* }
641647
* ```
642648
*/
643649
export class ZipReaderStream<T> {

0 commit comments

Comments
 (0)