解壓縮 gzip 檔案
在 Github 上編輯
如何解壓縮 gzip 檔案並將其儲存到磁碟的範例。
開啟 gzip 檔案以供讀取
const file = await Deno.open("large_file.json.gz");
建立新檔案以寫入解壓縮的資料
const outputPath = await Deno.create("large_file.json");
取得輸出檔案的可寫入串流
const writableStream = outputPath.writable;
為 gzip 格式建立解壓縮串流
const stream = new DecompressionStream("gzip");
將 gzip 檔案的可讀取串流通過解壓縮串流,然後傳輸到輸出檔案的可寫入串流
file.readable.pipeThrough(stream).pipeTo(writableStream);
使用 Deno CLI 在本機執行此範例
deno run --allow-write --allow-read https://deno-docs.dev.org.tw/examples/scripts/unzip_gzipped_file.ts