summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcos Casagrande <marcoscvp90@gmail.com>2020-10-19 13:33:51 +0200
committerGitHub <noreply@github.com>2020-10-19 13:33:51 +0200
commitd3dea24560f7434bd1020f0d9dc4c787f79479da (patch)
treea7245203f15dda13d52e1ca72a13c34a2859d070
parentf91c1155f0cccef9a49efdcc489be3f258000957 (diff)
fix(std/tar): fix constant condition (#8010)
-rw-r--r--std/archive/tar.ts9
-rw-r--r--std/archive/tar_test.ts10
2 files changed, 13 insertions, 6 deletions
diff --git a/std/archive/tar.ts b/std/archive/tar.ts
index a169d5b4b..0685ad837 100644
--- a/std/archive/tar.ts
+++ b/std/archive/tar.ts
@@ -485,7 +485,10 @@ class TarEntry implements Reader {
entryBytesLeft,
);
- if (entryBytesLeft <= 0) return null;
+ if (entryBytesLeft <= 0) {
+ this.#consumed = true;
+ return null;
+ }
const block = new Uint8Array(bufSize);
const n = await readBlock(this.#reader, block);
@@ -493,9 +496,7 @@ class TarEntry implements Reader {
this.#read += n || 0;
if (n === null || bytesLeft <= 0) {
- // FIXME(bartlomieju): this condition makes no sense
- // deno-lint-ignore no-constant-condition
- if (null) this.#consumed = true;
+ if (n === null) this.#consumed = true;
return null;
}
diff --git a/std/archive/tar_test.ts b/std/archive/tar_test.ts
index ff1ada4d5..cec98face 100644
--- a/std/archive/tar_test.ts
+++ b/std/archive/tar_test.ts
@@ -113,7 +113,9 @@ Deno.test("appendFileWithLongNameToTarArchive", async function (): Promise<
const untar = new Untar(tar.getReader());
const result = await untar.extract();
assert(result !== null);
+ assert(!result.consumed);
const untarText = new TextDecoder("utf-8").decode(await Deno.readAll(result));
+ assert(result.consumed);
// tests
assertEquals(result.fileName, fileName);
@@ -137,6 +139,7 @@ Deno.test("untarAsyncIterator", async function (): Promise<void> {
// read data from a tar archive
const untar = new Untar(tar.getReader());
+ let lastEntry;
for await (const entry of untar) {
const expected = entries.shift();
assert(expected);
@@ -145,11 +148,14 @@ Deno.test("untarAsyncIterator", async function (): Promise<void> {
if (expected.filePath) {
content = await Deno.readFile(expected.filePath);
}
-
assertEquals(content, await Deno.readAll(entry));
assertEquals(expected.name, entry.fileName);
- }
+ if (lastEntry) assert(lastEntry.consumed);
+ lastEntry = entry;
+ }
+ assert(lastEntry);
+ assert(lastEntry.consumed);
assertEquals(entries.length, 0);
});