Skip to content

Commit e55b874

Browse files
author
zhangfuxing
committed
fix: fix exists usage error
1 parent 8b8ed06 commit e55b874

File tree

22 files changed

+594
-117
lines changed

22 files changed

+594
-117
lines changed

README.md

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ If you want to read and write files, you need the following [permissions](https:
2222
2323
## `tar`
2424

25-
v0.5.4
25+
v0.5.5
2626
Use `@std/tar` instead of `@std/archive` due to deprecation
2727
If you want to use the old API, you can do it
2828

@@ -34,11 +34,11 @@ If you want to use the old API, you can do it
3434
// JSR
3535
import { tar } from "jsr:@deno-library/compress";
3636
// or
37-
// import { tar } from "jsr:@deno-library/[email protected].4";
37+
// import { tar } from "jsr:@deno-library/[email protected].5";
3838
// or
39-
// import { tar } from "https://deno.land/x/[email protected].4/mod.ts";
39+
// import { tar } from "https://deno.land/x/[email protected].5/mod.ts";
4040
// or only import tar
41-
// import { tar } from "https://deno.land/x/[email protected].4/tar/mod.ts";
41+
// import { tar } from "https://deno.land/x/[email protected].5/tar/mod.ts";
4242
export interface compressInterface {
4343
excludeSrc?: boolean; // does not contain the src directory
4444
debug?: boolean; // list the files and folders
@@ -56,7 +56,7 @@ tar.uncompress(src, dest, options?: uncompressInterface): Promise<void>;
5656
// JSR
5757
import { tar } from "jsr:@deno-library/compress";
5858
// or
59-
// import { tar } from "https://deno.land/x/[email protected].4/mod.ts";
59+
// import { tar } from "https://deno.land/x/[email protected].5/mod.ts";
6060
// compress folder
6161
await tar.compress("./test", "./test.tar");
6262
// compress folder, exclude src directory
@@ -83,9 +83,9 @@ import {
8383
inflateRaw,
8484
} from "jsr:@deno-library/compress";
8585
// or
86-
// import { deflate, inflate, deflateRaw, inflateRaw } from "https://deno.land/x/[email protected].4/mod.ts";
86+
// import { deflate, inflate, deflateRaw, inflateRaw } from "https://deno.land/x/[email protected].5/mod.ts";
8787
// or only import deflate, inflate, deflateRaw, inflateRaw
88-
// import { deflate, inflate, deflateRaw, inflateRaw } from "https://deno.land/x/[email protected].4/zlib/mod.ts";
88+
// import { deflate, inflate, deflateRaw, inflateRaw } from "https://deno.land/x/[email protected].5/zlib/mod.ts";
8989
const str = "hello world!";
9090
const bytes = new TextEncoder().encode(str);
9191
// with zlib header
@@ -128,9 +128,9 @@ Useful for reading and writing large files.
128128
```ts
129129
import { GzipStream } from "jsr:@deno-library/compress";
130130
// or
131-
// import { GzipStream } from "https://deno.land/x/[email protected].4/mod.ts";
131+
// import { GzipStream } from "https://deno.land/x/[email protected].5/mod.ts";
132132
// or only import GzipStream
133-
// import { GzipStream } from "https://deno.land/x/[email protected].4/gzip/mod.ts";
133+
// import { GzipStream } from "https://deno.land/x/[email protected].5/gzip/mod.ts";
134134
const gzip = new GzipStream();
135135
gzip.on("progress", (progress: string) => {
136136
console.log(progress); // 0.00% => 100.00%
@@ -145,9 +145,9 @@ await gzip.uncompress("./big.mkv.gz", "./big.mkv");
145145
```ts
146146
import { gunzipFile, gzipFile } from "jsr:@deno-library/compress";
147147
// or
148-
// import { gunzipFile, gzipFile } from "https://deno.land/x/[email protected].4/mod.ts";
148+
// import { gunzipFile, gzipFile } from "https://deno.land/x/[email protected].5/mod.ts";
149149
// or only import gzipFile, gunzipFile
150-
// import { gzipFile, gunzipFile } from "https://deno.land/x/[email protected].4/gzip/mod.ts";
150+
// import { gzipFile, gunzipFile } from "https://deno.land/x/[email protected].5/gzip/mod.ts";
151151
await gzipFile("./deno.txt", "./deno.txt.gz");
152152
await gunzipFile("./deno.txt.gz", "./deno.txt");
153153
```
@@ -160,9 +160,9 @@ await gunzipFile("./deno.txt.gz", "./deno.txt");
160160
```ts
161161
import { gunzip, gzip } from "jsr:@deno-library/compress";
162162
// or
163-
// import { gunzip, gzip } from "https://deno.land/x/[email protected].4/mod.ts";
163+
// import { gunzip, gzip } from "https://deno.land/x/[email protected].5/mod.ts";
164164
// or only import gzip, gunzip
165-
// import { gzip, gunzip } from "https://deno.land/x/[email protected].4/zlib/mod.ts";
165+
// import { gzip, gunzip } from "https://deno.land/x/[email protected].5/zlib/mod.ts";
166166
// gzip
167167
const bytes = new TextEncoder().encode("hello");
168168
const compressed = gzip(bytes);
@@ -172,7 +172,7 @@ const decompressed = gunzip(compressed);
172172

173173
## `tgz`
174174

175-
v0.5.4
175+
v0.5.5
176176
Use `@std/tar` instead of `@std/archive` due to deprecation
177177
If you want to use the old API, you can do it
178178

@@ -183,9 +183,9 @@ If you want to use the old API, you can do it
183183
```ts
184184
import { tgz } from "jsr:@deno-library/compress";
185185
// or
186-
// import { tgz } from "https://deno.land/x/[email protected].4/mod.ts";
186+
// import { tgz } from "https://deno.land/x/[email protected].5/mod.ts";
187187
// or only import tgz
188-
// import { tgz } from "https://deno.land/x/[email protected].4/tgz/mod.ts";
188+
// import { tgz } from "https://deno.land/x/[email protected].5/tgz/mod.ts";
189189
export interface compressInterface {
190190
excludeSrc?: boolean; // does not contain the src directory
191191
debug?: boolean; // list the files and folders
@@ -202,7 +202,7 @@ tgz.uncompress(src, dest, options?: uncompressInterface): Promise<void>;
202202
```ts
203203
import { tgz } from "jsr:@deno-library/compress";
204204
// or
205-
// import { tgz } from "https://deno.land/x/[email protected].4/mod.ts";
205+
// import { tgz } from "https://deno.land/x/[email protected].5/mod.ts";
206206
// compress folder
207207
await tgz.compress("./test", "./test.tar.gz");
208208
// compress folder, exclude src directory
@@ -220,9 +220,9 @@ await tgz.uncompress("./test.tar.gz", "./dest");
220220
```ts
221221
import { zip } from "jsr:@deno-library/compress";
222222
// or
223-
// import { zip } from "https://deno.land/x/[email protected].4/mod.ts";
223+
// import { zip } from "https://deno.land/x/[email protected].5/mod.ts";
224224
// or only import zip
225-
// import { zip } from "https://deno.land/x/[email protected].4/zip/mod.ts";
225+
// import { zip } from "https://deno.land/x/[email protected].5/zip/mod.ts";
226226

227227
export interface compressInterface {
228228
excludeSrc?: boolean; // does not contain the src directory
@@ -240,7 +240,7 @@ zip.uncompress(src, dest, options?: uncompressInterface): Promise<void>;
240240
```ts
241241
import { zip } from "jsr:@deno-library/compress";
242242
// or
243-
// import { zip } from "https://deno.land/x/[email protected].4/mod.ts";
243+
// import { zip } from "https://deno.land/x/[email protected].5/mod.ts";
244244
// compress folder
245245
await zip.compress("./test", "./test.tar.gz");
246246
// compress folder, exclude src directory

changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
## Changelog
22

3+
### v0.5.5 - 2024.11.20
4+
5+
- fix: fix exists usage error
6+
37
### v0.5.4 - 2024.11.20
48

59
- fix: zip.compress does not close the dest file if src does not exist[#19]

deflate/mod.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,14 @@
1+
/**
2+
* Compresses the input data using the DEFLATE algorithm.
3+
*
4+
* @param bytes - The input data as a Uint8Array to be compressed.
5+
* @param level - The compression level (default is DEFAULT_LEVEL).
6+
* @returns A Uint8Array containing the compressed data.
7+
*/
18
export { deflateRaw } from "./deflate_raw.ts";
9+
/**
10+
* Decompresses a raw Uint8Array data.
11+
* @param arr - The Uint8Array data to decompress.
12+
* @returns The decompressed Uint8Array data.
13+
*/
214
export { inflateRaw } from "./inflate_raw.ts";

deno.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"name": "@deno-library/compress",
3-
"version": "0.5.4",
3+
"version": "0.5.5",
44
"exports": "./mod.ts"
55
}

deps.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export { EventEmitter } from "node:events";
2-
export { ensureDir, exists } from "jsr:@std/[email protected]";
2+
export { ensureDir } from "jsr:@std/[email protected]";
33
export * as path from "jsr:@std/[email protected]";
44
export { Buffer, copy, readAll, writeAll } from "jsr:@std/[email protected]";
55
export { crc32, Crc32Stream } from "jsr:@deno-library/[email protected]";

tar/mod.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { compressInterface, uncompressInterface } from "../interface.ts";
2-
import { path, exists } from "../deps.ts";
2+
import { path } from "../deps.ts";
33
import { UntarStream } from "../deps.ts";
44
import { TarStream, type TarStreamInput } from "../deps.ts";
55

@@ -14,9 +14,13 @@ export async function uncompress(
1414
dest: string,
1515
options?: uncompressInterface,
1616
): Promise<void> {
17-
await exists(src, { isFile: true });
17+
const stat = await Deno.stat(src);
18+
if(stat.isDirectory) {
19+
throw new Error("The source path is a directory, not a file: ${src}")
20+
}
21+
using srcFile = await Deno.open(src);
1822
for await (
19-
const entry of (await Deno.open(src)).readable.pipeThrough(new UntarStream())
23+
const entry of srcFile.readable.pipeThrough(new UntarStream())
2024
) {
2125
const filePath = path.resolve(dest, entry.path);
2226
if (options?.debug) console.log(filePath);
@@ -36,8 +40,8 @@ export async function compress(
3640
dest: string,
3741
options?: compressInterface,
3842
): Promise<void> {
43+
const stat = await Deno.stat(src);
3944
const inputs: TarStreamInput[] = [];
40-
const stat = await Deno.lstat(src);
4145
if (stat.isFile) {
4246
inputs.push({
4347
type: "file",

tar_archive/mod.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Buffer, copy, ensureDir, exists, path } from "../deps.ts";
1+
import { Buffer, copy, ensureDir, path } from "../deps.ts";
22
import type { compressInterface, uncompressInterface } from "../interface.ts";
33
import { Tar } from "jsr:@std/[email protected]/tar";
44
import { Untar } from "jsr:@std/[email protected]/untar";
@@ -14,7 +14,10 @@ export async function uncompress(
1414
dest: string,
1515
options?: uncompressInterface,
1616
): Promise<void> {
17-
await exists(src, { isFile: true });
17+
const stat = await Deno.stat(src);
18+
if(stat.isDirectory) {
19+
throw new Error("The source path is a directory, not a file: ${src}")
20+
}
1821
using reader = await Deno.open(src, { read: true });
1922
const untar = new Untar(reader);
2023
for await (const entry of untar) {
@@ -44,7 +47,7 @@ export async function compress(
4447
options?: compressInterface,
4548
): Promise<void> {
4649
const tar = new Tar();
47-
const stat = await Deno.lstat(src);
50+
const stat = await Deno.stat(src);
4851
if (stat.isFile) {
4952
await tar.append(path.basename(src), {
5053
filePath: src,
@@ -118,7 +121,7 @@ export async function compress(
118121
// options?: compressInterface,
119122
// ): Promise<void> {
120123
// const tar = new Tar();
121-
// const stat = await Deno.lstat(src);
124+
// const stat = await Deno.stat(src);
122125
// if (stat.isFile) {
123126
// await tar.append(path.basename(src), {
124127
// filePath: src,

test/tar.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Deno.test("tar.compress file", async () => {
66
const dest = "./test.tar";
77
try {
88
await tar.compress(src, dest, { debug: true });
9-
const stat = await Deno.lstat(dest);
9+
const stat = await Deno.stat(dest);
1010
/**
1111
* 2048 = 512 (header) + 512 (content) + 1024 (footer)
1212
*/
@@ -23,7 +23,7 @@ Deno.test("tar.compress folder", async () => {
2323
const dest = "./test.tar";
2424
try {
2525
await tar.compress(src, dest, { debug: true });
26-
const stat = await Deno.lstat(dest);
26+
const stat = await Deno.stat(dest);
2727
/**
2828
* 4096 = 512 (header) + 0 (content) + // tar folder
2929
* 512 (header) + 512 (content) + // tar.txt
@@ -47,7 +47,7 @@ Deno.test("tar.uncompress", async () => {
4747
const landTxtContent = "land\n";
4848
try {
4949
await tar.uncompress(src, dest, { debug: true });
50-
const stat = await Deno.lstat(landTxtPath);
50+
const stat = await Deno.stat(landTxtPath);
5151
assertEquals(stat.size, landTxtSize);
5252
const buf = await Deno.readFile(landTxtPath);
5353
const content = new TextDecoder().decode(buf);

test/zip.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Deno.test("zip.compress file", async () => {
66
const dest = "./test.zip";
77
try {
88
await zip.compress(src, dest, { debug: true });
9-
const stat = await Deno.lstat(dest);
9+
const stat = await Deno.stat(dest);
1010
assertEquals(stat.size, 255);
1111
await Deno.remove(dest);
1212
} catch (error) {
@@ -20,7 +20,7 @@ Deno.test("zip.compress folder", async () => {
2020
const dest = "./deno.zip";
2121
try {
2222
await zip.compress(src, dest, { debug: true });
23-
const stat = await Deno.lstat(dest);
23+
const stat = await Deno.stat(dest);
2424
assertEquals(stat.size, 943);
2525
await Deno.remove(dest);
2626
} catch (error) {

tgz/mod.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { compressInterface, uncompressInterface } from "../interface.ts";
2-
import { exists, path } from "../deps.ts";
2+
import { path } from "../deps.ts";
33
import { UntarStream } from "../deps.ts";
44
import { TarStream, type TarStreamInput } from "../deps.ts";
55

@@ -22,9 +22,13 @@ export async function uncompress(
2222
dest: string,
2323
options?: uncompressInterface,
2424
): Promise<void> {
25-
await exists(src, { isFile: true });
25+
const stat = await Deno.stat(src);
26+
if(stat.isDirectory) {
27+
throw new Error("The source path is a directory, not a file: ${src}")
28+
}
29+
using srcFile = await Deno.open(src);
2630
for await (
27-
const entry of (await Deno.open(src)).readable.pipeThrough(
31+
const entry of srcFile.readable.pipeThrough(
2832
new DecompressionStream("gzip"),
2933
).pipeThrough(new UntarStream())
3034
) {
@@ -47,8 +51,8 @@ export async function compress(
4751
dest: string,
4852
options?: compressInterface,
4953
): Promise<void> {
54+
const stat = await Deno.stat(src);
5055
const inputs: TarStreamInput[] = [];
51-
const stat = await Deno.lstat(src);
5256
if (stat.isFile) {
5357
inputs.push({
5458
type: "file",

0 commit comments

Comments
 (0)