Skip to content

Commit 2bf2450

Browse files
committed
WIP
1 parent 8015a5e commit 2bf2450

File tree

5 files changed

+2717
-11
lines changed

5 files changed

+2717
-11
lines changed

READMEOTHER.md

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# VirtualTar
2+
3+
This only exposes `extract` and `pack`.
4+
5+
6+
You can `pack()` a directory and pipe it as stream.
7+
8+
You can pipe a stream into `tar.extract()`.
9+
10+
So it just uses `tar-stream`. But what about direct access to the tar stream?
11+
12+
When you pack, it accepts a bunch of callbacks.
13+
14+
And it uses the `fs`, but we want it to accept a `fs` parameter, preferably with `VirtualFS`.
15+
16+
So it can be isolated, and if we can have direct access to the `tar-stream` too.
17+
18+
```
19+
ignore
20+
```
21+
22+
The `pack` takes `cwd` and `opts`.
23+
24+
Oh it takes the `fs` parameter. Cool. So it's just `xfs = opts.fs || fs`. So if we pass it a virtualfs. Then we can just create it there then!
25+
26+
Wait... it's still using `fs`... Oh...
27+
Ok so all we need to do is ignore fs.
28+
29+
```
30+
var vfs = require('virtualfs');
31+
var tar = require('./index.js');
32+
33+
var fs = new vfs.VirtualFS;
34+
35+
fs.mkdirSync('/dir');
36+
fs.writeFileSync('/dir/a', 'abc');
37+
38+
tar.pack('/dir', {
39+
fs: fs
40+
});
41+
```
42+
43+
Ok so this works. We just need to pass our vfs into it.
44+
45+
And everything else is fine.

index.js

+29-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,32 @@
1-
var chownr = require('chownr')
2-
var tar = require('tar-stream')
3-
var pump = require('pump')
4-
var mkdirp = require('mkdirp')
5-
var fs = require('fs')
6-
var path = require('path')
7-
var os = require('os')
1+
import pathNode from 'path';
2+
import tar from 'tar-stream';
3+
import vfs from 'virtualfs';
4+
5+
// prefer posix join
6+
const pathJoin = (pathNode.posix) ? pathNode.posix.join : pathNode.join;
7+
8+
9+
// we already have mkdirp
10+
// no need for it
11+
12+
13+
// the default is more improtant there
14+
15+
16+
17+
18+
// we need to implement chownr into the virtualfs
19+
// it's recursive
20+
// so we keep going down
21+
22+
23+
// var chownr = require('chownr')
24+
// var tar = require('tar-stream')
25+
// var pump = require('pump')
26+
// var mkdirp = require('mkdirp')
27+
// var path = require('path')
28+
// var os = require('os')
29+
830

931
var win32 = os.platform() === 'win32'
1032

mytarball.tar

4 KB
Binary file not shown.

0 commit comments

Comments
 (0)