forked from kevva/decompress-tar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
46 lines (36 loc) · 1.23 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import fs from 'fs';
import path from 'path';
import isJpg from 'is-jpg';
import pify from 'pify';
import test from 'ava';
import m from '.';
const fsP = pify(fs);
test('extract file', async t => {
const buf = await fsP.readFile(path.join(__dirname, 'fixtures', 'file.tar'));
const files = await m()(buf);
t.is(files[0].path, 'test.jpg');
t.true(isJpg(files[0].data));
});
test('extract file using streams', async t => {
const stream = fs.createReadStream(path.join(__dirname, 'fixtures', 'file.tar'));
const files = await m()(stream);
t.is(files[0].path, 'test.jpg');
t.true(isJpg(files[0].data));
});
test('extract symlinks', async t => {
const buf = await fsP.readFile(path.join(__dirname, 'fixtures', 'symlink.tar'));
const files = await m()(buf);
t.is(files[0].path, 'test-symlink/symlink');
t.is(files[0].type, 'symlink');
t.is(files[0].linkname, 'file.txt');
t.is(files[1].path, 'test-symlink/file.txt');
t.is(files[1].type, 'file');
});
test('return empty array if non-valid file is supplied', async t => {
const buf = await fsP.readFile(__filename);
const files = await m()(buf);
t.is(files.length, 0);
});
test('throw on wrong input', async t => {
await t.throws(m()('foo'), 'Expected a Buffer or Stream, got string');
});