Skip to content

Commit

Permalink
Updating EmscriptenFS so it can use secondary FS modules. Releasing 0…
Browse files Browse the repository at this point in the history
….5.3.
  • Loading branch information
John Vilk committed Nov 8, 2015
1 parent 92fc3c6 commit d1563f3
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 67 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# BrowserFS v0.5.2
# BrowserFS v0.5.3
> BrowserFS is an in-browser file system that emulates the [Node JS file system API](http://nodejs.org/api/fs.html) and supports storing and retrieving files from various backends. BrowserFS also integrates nicely into the Emscripten file system.
[![NPM version](https://badge.fury.io/js/browserfs.svg)](http://badge.fury.io/js/browserfs)
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "BrowserFS",
"version": "0.5.2",
"version": "0.5.3",
"main": [
"./dist/browserfs.min.js",
"./dist/browserfs.min.js.map"
Expand Down
45 changes: 26 additions & 19 deletions dist/browserfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -12270,6 +12270,7 @@ var util_1 = _dereq_('../core/util');
var BFSEmscriptenStreamOps = (function () {
function BFSEmscriptenStreamOps(fs) {
this.fs = fs;
this.nodefs = fs.getNodeFS();
this.FS = fs.getFS();
this.PATH = fs.getPATH();
this.ERRNO_CODES = fs.getERRNO_CODES();
Expand All @@ -12278,7 +12279,7 @@ var BFSEmscriptenStreamOps = (function () {
var path = this.fs.realPath(stream.node), FS = this.FS;
try {
if (FS.isFile(stream.node.mode)) {
stream.nfd = fs.openSync(path, this.fs.flagsToPermissionString(stream.flags));
stream.nfd = this.nodefs.openSync(path, this.fs.flagsToPermissionString(stream.flags));
}
}
catch (e) {
Expand All @@ -12291,7 +12292,7 @@ var BFSEmscriptenStreamOps = (function () {
var FS = this.FS;
try {
if (FS.isFile(stream.node.mode) && stream.nfd) {
fs.closeSync(stream.nfd);
this.nodefs.closeSync(stream.nfd);
}
}
catch (e) {
Expand All @@ -12302,15 +12303,15 @@ var BFSEmscriptenStreamOps = (function () {
};
BFSEmscriptenStreamOps.prototype.read = function (stream, buffer, offset, length, position) {
try {
return fs.readSync(stream.nfd, util_1.uint8Array2Buffer(buffer), offset, length, position);
return this.nodefs.readSync(stream.nfd, util_1.uint8Array2Buffer(buffer), offset, length, position);
}
catch (e) {
throw new this.FS.ErrnoError(this.ERRNO_CODES[e.code]);
}
};
BFSEmscriptenStreamOps.prototype.write = function (stream, buffer, offset, length, position) {
try {
return fs.writeSync(stream.nfd, util_1.uint8Array2Buffer(buffer), offset, length, position);
return this.nodefs.writeSync(stream.nfd, util_1.uint8Array2Buffer(buffer), offset, length, position);
}
catch (e) {
throw new this.FS.ErrnoError(this.ERRNO_CODES[e.code]);
Expand All @@ -12324,7 +12325,7 @@ var BFSEmscriptenStreamOps = (function () {
else if (whence === 2) {
if (this.FS.isFile(stream.node.mode)) {
try {
var stat = fs.fstatSync(stream.nfd);
var stat = this.nodefs.fstatSync(stream.nfd);
position += stat.size;
}
catch (e) {
Expand All @@ -12343,6 +12344,7 @@ var BFSEmscriptenStreamOps = (function () {
var BFSEmscriptenNodeOps = (function () {
function BFSEmscriptenNodeOps(fs) {
this.fs = fs;
this.nodefs = fs.getNodeFS();
this.FS = fs.getFS();
this.PATH = fs.getPATH();
this.ERRNO_CODES = fs.getERRNO_CODES();
Expand All @@ -12351,7 +12353,7 @@ var BFSEmscriptenNodeOps = (function () {
var path = this.fs.realPath(node);
var stat;
try {
stat = fs.lstatSync(path);
stat = this.nodefs.lstatSync(path);
}
catch (e) {
if (!e.code)
Expand All @@ -12378,12 +12380,12 @@ var BFSEmscriptenNodeOps = (function () {
var path = this.fs.realPath(node);
try {
if (attr.mode !== undefined) {
fs.chmodSync(path, attr.mode);
this.nodefs.chmodSync(path, attr.mode);
node.mode = attr.mode;
}
if (attr.timestamp !== undefined) {
var date = new Date(attr.timestamp);
fs.utimesSync(path, date, date);
this.nodefs.utimesSync(path, date, date);
}
}
catch (e) {
Expand All @@ -12395,7 +12397,7 @@ var BFSEmscriptenNodeOps = (function () {
}
if (attr.size !== undefined) {
try {
fs.truncateSync(path, attr.size);
this.nodefs.truncateSync(path, attr.size);
}
catch (e) {
if (!e.code)
Expand All @@ -12414,10 +12416,10 @@ var BFSEmscriptenNodeOps = (function () {
var path = this.fs.realPath(node);
try {
if (this.FS.isDir(node.mode)) {
fs.mkdirSync(path, node.mode);
this.nodefs.mkdirSync(path, node.mode);
}
else {
fs.writeFileSync(path, '', { mode: node.mode });
this.nodefs.writeFileSync(path, '', { mode: node.mode });
}
}
catch (e) {
Expand All @@ -12431,7 +12433,7 @@ var BFSEmscriptenNodeOps = (function () {
var oldPath = this.fs.realPath(oldNode);
var newPath = this.PATH.join2(this.fs.realPath(newDir), newName);
try {
fs.renameSync(oldPath, newPath);
this.nodefs.renameSync(oldPath, newPath);
}
catch (e) {
if (!e.code)
Expand All @@ -12442,7 +12444,7 @@ var BFSEmscriptenNodeOps = (function () {
BFSEmscriptenNodeOps.prototype.unlink = function (parent, name) {
var path = this.PATH.join2(this.fs.realPath(parent), name);
try {
fs.unlinkSync(path);
this.nodefs.unlinkSync(path);
}
catch (e) {
if (!e.code)
Expand All @@ -12453,7 +12455,7 @@ var BFSEmscriptenNodeOps = (function () {
BFSEmscriptenNodeOps.prototype.rmdir = function (parent, name) {
var path = this.PATH.join2(this.fs.realPath(parent), name);
try {
fs.rmdirSync(path);
this.nodefs.rmdirSync(path);
}
catch (e) {
if (!e.code)
Expand All @@ -12464,7 +12466,7 @@ var BFSEmscriptenNodeOps = (function () {
BFSEmscriptenNodeOps.prototype.readdir = function (node) {
var path = this.fs.realPath(node);
try {
return fs.readdirSync(path);
return this.nodefs.readdirSync(path);
}
catch (e) {
if (!e.code)
Expand All @@ -12475,7 +12477,7 @@ var BFSEmscriptenNodeOps = (function () {
BFSEmscriptenNodeOps.prototype.symlink = function (parent, newName, oldPath) {
var newPath = this.PATH.join2(this.fs.realPath(parent), newName);
try {
fs.symlinkSync(oldPath, newPath);
this.nodefs.symlinkSync(oldPath, newPath);
}
catch (e) {
if (!e.code)
Expand All @@ -12486,7 +12488,7 @@ var BFSEmscriptenNodeOps = (function () {
BFSEmscriptenNodeOps.prototype.readlink = function (node) {
var path = this.fs.realPath(node);
try {
return fs.readlinkSync(path);
return this.nodefs.readlinkSync(path);
}
catch (e) {
if (!e.code)
Expand All @@ -12497,10 +12499,11 @@ var BFSEmscriptenNodeOps = (function () {
return BFSEmscriptenNodeOps;
})();
var BFSEmscriptenFS = (function () {
function BFSEmscriptenFS(_FS, _PATH, _ERRNO_CODES) {
function BFSEmscriptenFS(_FS, _PATH, _ERRNO_CODES, nodefs) {
if (_FS === void 0) { _FS = self['FS']; }
if (_PATH === void 0) { _PATH = self['PATH']; }
if (_ERRNO_CODES === void 0) { _ERRNO_CODES = self['ERRNO_CODES']; }
if (nodefs === void 0) { nodefs = fs; }
this.flagsToPermissionStringMap = {
0: 'r',
1: 'r+',
Expand Down Expand Up @@ -12530,6 +12533,7 @@ var BFSEmscriptenFS = (function () {
if (typeof BrowserFS === 'undefined') {
throw new Error("BrowserFS is not loaded. Please load it before this library.");
}
this.nodefs = nodefs;
this.FS = _FS;
this.PATH = _PATH;
this.ERRNO_CODES = _ERRNO_CODES;
Expand All @@ -12552,7 +12556,7 @@ var BFSEmscriptenFS = (function () {
BFSEmscriptenFS.prototype.getMode = function (path) {
var stat;
try {
stat = fs.lstatSync(path);
stat = this.nodefs.lstatSync(path);
}
catch (e) {
if (!e.code)
Expand Down Expand Up @@ -12581,6 +12585,9 @@ var BFSEmscriptenFS = (function () {
return flags;
}
};
BFSEmscriptenFS.prototype.getNodeFS = function () {
return this.nodefs;
};
BFSEmscriptenFS.prototype.getFS = function () {
return this.FS;
};
Expand Down
4 changes: 2 additions & 2 deletions dist/browserfs.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/browserfs.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/browserfs.min.js.map

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion dist/node/generic/emscripten_fs.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import FS from '../core/FS';
export interface Stats {
dev: number;
ino: number;
Expand Down Expand Up @@ -67,7 +68,8 @@ export default class BFSEmscriptenFS implements EmscriptenFS {
private FS;
private PATH;
private ERRNO_CODES;
constructor(_FS?: any, _PATH?: any, _ERRNO_CODES?: any);
private nodefs;
constructor(_FS?: any, _PATH?: any, _ERRNO_CODES?: any, nodefs?: FS);
mount(mount: {
opts: {
root: string;
Expand Down Expand Up @@ -103,6 +105,7 @@ export default class BFSEmscriptenFS implements EmscriptenFS {
4098: string;
};
flagsToPermissionString(flags: string): string;
getNodeFS(): FS;
getFS(): any;
getPATH(): any;
getERRNO_CODES(): any;
Expand Down
Loading

0 comments on commit d1563f3

Please sign in to comment.