Skip to content

Commit

Permalink
test: validate that files can be read from tar successfully
Browse files Browse the repository at this point in the history
  • Loading branch information
blacha committed Nov 3, 2021
1 parent f9cad76 commit 574c870
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions packages/core/src/__test__/tar.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/** Start Header */
import { SourceMemory } from '@chunkd/core';
import { SourceFile } from '@chunkd/source-file';
import * as cp from 'child_process';
Expand All @@ -17,7 +18,7 @@ o.spec('TarReader', () => {
o.before(() => {
cp.execSync(`tar cf ${tarFilePath} tar.test.*`, { cwd: __dirname });
});
const tarFilePath = path.join(__dirname, 'test.tar');
const tarFilePath = path.join(__dirname, '_test.tar');

let fd: FileHandle | null;
const headBuffer = Buffer.alloc(512);
Expand All @@ -44,14 +45,16 @@ o.spec('TarReader', () => {

const res = await CotarIndexBuilder.create(source);

await source.close();

const index = await CotarIndex.create(new SourceMemory('index', res.buffer));
o(res.count >= 3).equals(true);

const tarTest = await index.find('tar.test.js');
o(tarTest).notEquals(null);
o(tarTest?.size).equals(tarTestStat.size);

const buf = Buffer.alloc(tarTest?.size ?? 0);
await source.read(buf, 0, tarTest?.size, tarTest?.offset);
o(buf.toString().startsWith(`/** Start Header */`)).equals(true);
});

o('should work with a .tar.co', async () => {
Expand All @@ -70,5 +73,10 @@ o.spec('TarReader', () => {
const tarTest = await cotar.index.find('tar.test.js');
o(tarTest).notEquals(null);
o(tarTest?.size).equals(tarTestStat.size);

const data = await cotar.get('tar.test.js');
o(data).notEquals(null);
const buf = Buffer.from(data!.slice(0, 100));
o(buf.toString().startsWith(`/** Start Header */`)).equals(true);
});
});

0 comments on commit 574c870

Please sign in to comment.