-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
zhangfuxing
committed
Nov 20, 2024
1 parent
8b8ed06
commit e55b874
Showing
22 changed files
with
594 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,7 @@ If you want to read and write files, you need the following [permissions](https: | |
## `tar` | ||
|
||
v0.5.4 | ||
v0.5.5 | ||
Use `@std/tar` instead of `@std/archive` due to deprecation | ||
If you want to use the old API, you can do it | ||
|
||
|
@@ -34,11 +34,11 @@ If you want to use the old API, you can do it | |
// JSR | ||
import { tar } from "jsr:@deno-library/compress"; | ||
// or | ||
// import { tar } from "jsr:@deno-library/[email protected].4"; | ||
// import { tar } from "jsr:@deno-library/[email protected].5"; | ||
// or | ||
// import { tar } from "https://deno.land/x/[email protected].4/mod.ts"; | ||
// import { tar } from "https://deno.land/x/[email protected].5/mod.ts"; | ||
// or only import tar | ||
// import { tar } from "https://deno.land/x/[email protected].4/tar/mod.ts"; | ||
// import { tar } from "https://deno.land/x/[email protected].5/tar/mod.ts"; | ||
export interface compressInterface { | ||
excludeSrc?: boolean; // does not contain the src directory | ||
debug?: boolean; // list the files and folders | ||
|
@@ -56,7 +56,7 @@ tar.uncompress(src, dest, options?: uncompressInterface): Promise<void>; | |
// JSR | ||
import { tar } from "jsr:@deno-library/compress"; | ||
// or | ||
// import { tar } from "https://deno.land/x/[email protected].4/mod.ts"; | ||
// import { tar } from "https://deno.land/x/[email protected].5/mod.ts"; | ||
// compress folder | ||
await tar.compress("./test", "./test.tar"); | ||
// compress folder, exclude src directory | ||
|
@@ -83,9 +83,9 @@ import { | |
inflateRaw, | ||
} from "jsr:@deno-library/compress"; | ||
// or | ||
// import { deflate, inflate, deflateRaw, inflateRaw } from "https://deno.land/x/[email protected].4/mod.ts"; | ||
// import { deflate, inflate, deflateRaw, inflateRaw } from "https://deno.land/x/[email protected].5/mod.ts"; | ||
// or only import deflate, inflate, deflateRaw, inflateRaw | ||
// import { deflate, inflate, deflateRaw, inflateRaw } from "https://deno.land/x/[email protected].4/zlib/mod.ts"; | ||
// import { deflate, inflate, deflateRaw, inflateRaw } from "https://deno.land/x/[email protected].5/zlib/mod.ts"; | ||
const str = "hello world!"; | ||
const bytes = new TextEncoder().encode(str); | ||
// with zlib header | ||
|
@@ -128,9 +128,9 @@ Useful for reading and writing large files. | |
```ts | ||
import { GzipStream } from "jsr:@deno-library/compress"; | ||
// or | ||
// import { GzipStream } from "https://deno.land/x/[email protected].4/mod.ts"; | ||
// import { GzipStream } from "https://deno.land/x/[email protected].5/mod.ts"; | ||
// or only import GzipStream | ||
// import { GzipStream } from "https://deno.land/x/[email protected].4/gzip/mod.ts"; | ||
// import { GzipStream } from "https://deno.land/x/[email protected].5/gzip/mod.ts"; | ||
const gzip = new GzipStream(); | ||
gzip.on("progress", (progress: string) => { | ||
console.log(progress); // 0.00% => 100.00% | ||
|
@@ -145,9 +145,9 @@ await gzip.uncompress("./big.mkv.gz", "./big.mkv"); | |
```ts | ||
import { gunzipFile, gzipFile } from "jsr:@deno-library/compress"; | ||
// or | ||
// import { gunzipFile, gzipFile } from "https://deno.land/x/[email protected].4/mod.ts"; | ||
// import { gunzipFile, gzipFile } from "https://deno.land/x/[email protected].5/mod.ts"; | ||
// or only import gzipFile, gunzipFile | ||
// import { gzipFile, gunzipFile } from "https://deno.land/x/[email protected].4/gzip/mod.ts"; | ||
// import { gzipFile, gunzipFile } from "https://deno.land/x/[email protected].5/gzip/mod.ts"; | ||
await gzipFile("./deno.txt", "./deno.txt.gz"); | ||
await gunzipFile("./deno.txt.gz", "./deno.txt"); | ||
``` | ||
|
@@ -160,9 +160,9 @@ await gunzipFile("./deno.txt.gz", "./deno.txt"); | |
```ts | ||
import { gunzip, gzip } from "jsr:@deno-library/compress"; | ||
// or | ||
// import { gunzip, gzip } from "https://deno.land/x/[email protected].4/mod.ts"; | ||
// import { gunzip, gzip } from "https://deno.land/x/[email protected].5/mod.ts"; | ||
// or only import gzip, gunzip | ||
// import { gzip, gunzip } from "https://deno.land/x/[email protected].4/zlib/mod.ts"; | ||
// import { gzip, gunzip } from "https://deno.land/x/[email protected].5/zlib/mod.ts"; | ||
// gzip | ||
const bytes = new TextEncoder().encode("hello"); | ||
const compressed = gzip(bytes); | ||
|
@@ -172,7 +172,7 @@ const decompressed = gunzip(compressed); | |
|
||
## `tgz` | ||
|
||
v0.5.4 | ||
v0.5.5 | ||
Use `@std/tar` instead of `@std/archive` due to deprecation | ||
If you want to use the old API, you can do it | ||
|
||
|
@@ -183,9 +183,9 @@ If you want to use the old API, you can do it | |
```ts | ||
import { tgz } from "jsr:@deno-library/compress"; | ||
// or | ||
// import { tgz } from "https://deno.land/x/[email protected].4/mod.ts"; | ||
// import { tgz } from "https://deno.land/x/[email protected].5/mod.ts"; | ||
// or only import tgz | ||
// import { tgz } from "https://deno.land/x/[email protected].4/tgz/mod.ts"; | ||
// import { tgz } from "https://deno.land/x/[email protected].5/tgz/mod.ts"; | ||
export interface compressInterface { | ||
excludeSrc?: boolean; // does not contain the src directory | ||
debug?: boolean; // list the files and folders | ||
|
@@ -202,7 +202,7 @@ tgz.uncompress(src, dest, options?: uncompressInterface): Promise<void>; | |
```ts | ||
import { tgz } from "jsr:@deno-library/compress"; | ||
// or | ||
// import { tgz } from "https://deno.land/x/[email protected].4/mod.ts"; | ||
// import { tgz } from "https://deno.land/x/[email protected].5/mod.ts"; | ||
// compress folder | ||
await tgz.compress("./test", "./test.tar.gz"); | ||
// compress folder, exclude src directory | ||
|
@@ -220,9 +220,9 @@ await tgz.uncompress("./test.tar.gz", "./dest"); | |
```ts | ||
import { zip } from "jsr:@deno-library/compress"; | ||
// or | ||
// import { zip } from "https://deno.land/x/[email protected].4/mod.ts"; | ||
// import { zip } from "https://deno.land/x/[email protected].5/mod.ts"; | ||
// or only import zip | ||
// import { zip } from "https://deno.land/x/[email protected].4/zip/mod.ts"; | ||
// import { zip } from "https://deno.land/x/[email protected].5/zip/mod.ts"; | ||
|
||
export interface compressInterface { | ||
excludeSrc?: boolean; // does not contain the src directory | ||
|
@@ -240,7 +240,7 @@ zip.uncompress(src, dest, options?: uncompressInterface): Promise<void>; | |
```ts | ||
import { zip } from "jsr:@deno-library/compress"; | ||
// or | ||
// import { zip } from "https://deno.land/x/[email protected].4/mod.ts"; | ||
// import { zip } from "https://deno.land/x/[email protected].5/mod.ts"; | ||
// compress folder | ||
await zip.compress("./test", "./test.tar.gz"); | ||
// compress folder, exclude src directory | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,14 @@ | ||
/** | ||
* Compresses the input data using the DEFLATE algorithm. | ||
* | ||
* @param bytes - The input data as a Uint8Array to be compressed. | ||
* @param level - The compression level (default is DEFAULT_LEVEL). | ||
* @returns A Uint8Array containing the compressed data. | ||
*/ | ||
export { deflateRaw } from "./deflate_raw.ts"; | ||
/** | ||
* Decompresses a raw Uint8Array data. | ||
* @param arr - The Uint8Array data to decompress. | ||
* @returns The decompressed Uint8Array data. | ||
*/ | ||
export { inflateRaw } from "./inflate_raw.ts"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"name": "@deno-library/compress", | ||
"version": "0.5.4", | ||
"version": "0.5.5", | ||
"exports": "./mod.ts" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
export { EventEmitter } from "node:events"; | ||
export { ensureDir, exists } from "jsr:@std/[email protected]"; | ||
export { ensureDir } from "jsr:@std/[email protected]"; | ||
export * as path from "jsr:@std/[email protected]"; | ||
export { Buffer, copy, readAll, writeAll } from "jsr:@std/[email protected]"; | ||
export { crc32, Crc32Stream } from "jsr:@deno-library/[email protected]"; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { Buffer, copy, ensureDir, exists, path } from "../deps.ts"; | ||
import { Buffer, copy, ensureDir, path } from "../deps.ts"; | ||
import type { compressInterface, uncompressInterface } from "../interface.ts"; | ||
import { Tar } from "jsr:@std/[email protected]/tar"; | ||
import { Untar } from "jsr:@std/[email protected]/untar"; | ||
|
@@ -14,7 +14,10 @@ export async function uncompress( | |
dest: string, | ||
options?: uncompressInterface, | ||
): Promise<void> { | ||
await exists(src, { isFile: true }); | ||
const stat = await Deno.stat(src); | ||
if(stat.isDirectory) { | ||
throw new Error("The source path is a directory, not a file: ${src}") | ||
} | ||
using reader = await Deno.open(src, { read: true }); | ||
const untar = new Untar(reader); | ||
for await (const entry of untar) { | ||
|
@@ -44,7 +47,7 @@ export async function compress( | |
options?: compressInterface, | ||
): Promise<void> { | ||
const tar = new Tar(); | ||
const stat = await Deno.lstat(src); | ||
const stat = await Deno.stat(src); | ||
if (stat.isFile) { | ||
await tar.append(path.basename(src), { | ||
filePath: src, | ||
|
@@ -118,7 +121,7 @@ export async function compress( | |
// options?: compressInterface, | ||
// ): Promise<void> { | ||
// const tar = new Tar(); | ||
// const stat = await Deno.lstat(src); | ||
// const stat = await Deno.stat(src); | ||
// if (stat.isFile) { | ||
// await tar.append(path.basename(src), { | ||
// filePath: src, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.