forked from szastupov/zipread
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzipfs.js
43 lines (35 loc) · 822 Bytes
/
zipfs.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
var Archive = require('./archive.js');
function ZipFS(path) {
this.path = path;
this.zip = new Archive(path);
this._pkgCache = {};
}
ZipFS.prototype = {
readFileSync: function(path, encoding) {
return this.zip.readFileSync(path, encoding);
},
statSync: function(path) {
if (!this.zip.exists(path)) {
throw new Error(path+" doesn't exist");
}
var file = this.zip.files[path];
return {
isDirectory: function () {
return file.dir;
},
isFile: function () {
return !file.dir;
}
};
},
existsSync: function (path) {
return this.zip.exists(path);
},
readdirSync: function(dir) {
return this.zip.readdir(dir);
},
realpathSync: function(path) {
return Archive.zjoin(this.path, path);
}
};
module.exports = ZipFS;