Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

memfs

Package Overview
Dependencies
Maintainers
1
Versions
154
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

memfs - npm Package Compare versions

Comparing version 4.1.0 to 4.2.0

demo/runkit.js

1

lib/__tests__/util.js

@@ -30,1 +30,2 @@ "use strict";

exports.onlyOnNode20 = nodeMajorVersion >= 20 ? describe : describe.skip;
//# sourceMappingURL=util.js.map

@@ -52,1 +52,2 @@ "use strict";

};
//# sourceMappingURL=constants.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=AMODE.js.map

@@ -0,1 +1,7 @@

/**
* Constants used in `open` system calls, see [open(2)](http://man7.org/linux/man-pages/man2/open.2.html).
*
* @see http://man7.org/linux/man-pages/man2/open.2.html
* @see https://www.gnu.org/software/libc/manual/html_node/Open_002dtime-Flags.html
*/
export declare const enum FLAG {

@@ -2,0 +8,0 @@ O_RDONLY = 0,

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=FLAG.js.map

@@ -49,1 +49,2 @@ "use strict";

exports.default = Dirent;
//# sourceMappingURL=Dirent.js.map

@@ -20,1 +20,2 @@ "use strict";

exports.strToEncoding = strToEncoding;
//# sourceMappingURL=encoding.js.map

705

lib/fsa-to-node/__tests__/FsaNodeFs.test.js
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -18,12 +9,12 @@ const __1 = require("../..");

const setup = (json = null, mode = 'readwrite') => {
const mfs = (0, __1.memfs)({ mountpoint: json });
const { fs: mfs, vol } = (0, __1.memfs)({ mountpoint: json });
const dir = (0, node_to_fsa_1.nodeToFsa)(mfs, '/mountpoint', { mode, syncHandleAllowed: true });
const fs = new FsaNodeFs_1.FsaNodeFs(dir);
return { fs, mfs, dir };
return { fs, mfs, vol, dir };
};
(0, util_1.onlyOnNode20)('FsaNodeFs', () => {
describe('.mkdir()', () => {
test('can create a sub-folder', () => __awaiter(void 0, void 0, void 0, function* () {
test('can create a sub-folder', async () => {
const { fs, mfs } = setup();
yield new Promise((resolve, reject) => fs.mkdir('/test', err => {
await new Promise((resolve, reject) => fs.mkdir('/test', err => {
if (err)

@@ -34,7 +25,16 @@ return reject(err);

expect(mfs.statSync('/mountpoint/test').isDirectory()).toBe(true);
}));
test('throws when creating sub-sub-folder', () => __awaiter(void 0, void 0, void 0, function* () {
});
test('can create a sub-folder with trailing slash', async () => {
const { fs, mfs } = setup();
await new Promise((resolve, reject) => fs.mkdir('/test/', err => {
if (err)
return reject(err);
return resolve();
}));
expect(mfs.statSync('/mountpoint/test').isDirectory()).toBe(true);
});
test('throws when creating sub-sub-folder', async () => {
const { fs } = setup();
try {
yield new Promise((resolve, reject) => fs.mkdir('/test/subtest', err => {
await new Promise((resolve, reject) => fs.mkdir('/test/subtest', err => {
if (err)

@@ -49,6 +49,6 @@ return reject(err);

}
}));
test('can create sub-sub-folder with "recursive" flag', () => __awaiter(void 0, void 0, void 0, function* () {
});
test('can create sub-sub-folder with "recursive" flag', async () => {
const { fs, mfs } = setup();
yield new Promise((resolve, reject) => fs.mkdir('/test/subtest', { recursive: true }, err => {
await new Promise((resolve, reject) => fs.mkdir('/test/subtest', { recursive: true }, err => {
if (err)

@@ -59,12 +59,12 @@ return reject(err);

expect(mfs.statSync('/mountpoint/test/subtest').isDirectory()).toBe(true);
}));
test('can create sub-sub-folder with "recursive" flag with Promises API', () => __awaiter(void 0, void 0, void 0, function* () {
});
test('can create sub-sub-folder with "recursive" flag with Promises API', async () => {
const { fs, mfs } = setup();
yield fs.promises.mkdir('/test/subtest', { recursive: true });
await fs.promises.mkdir('/test/subtest', { recursive: true });
expect(mfs.statSync('/mountpoint/test/subtest').isDirectory()).toBe(true);
}));
test('cannot create a folder over a file', () => __awaiter(void 0, void 0, void 0, function* () {
});
test('cannot create a folder over a file', async () => {
const { fs } = setup({ file: 'test' });
try {
yield fs.promises.mkdir('/file/folder', { recursive: true });
await fs.promises.mkdir('/file/folder', { recursive: true });
throw new Error('Expected error');

@@ -75,22 +75,22 @@ }

}
}));
});
});
describe('.mkdtemp()', () => {
test('can create a temporary folder', () => __awaiter(void 0, void 0, void 0, function* () {
test('can create a temporary folder', async () => {
const { fs, mfs } = setup();
const dirname = (yield fs.promises.mkdtemp('prefix--'));
const dirname = (await fs.promises.mkdtemp('prefix--'));
expect(dirname.startsWith('prefix--')).toBe(true);
expect(mfs.statSync('/mountpoint/' + dirname).isDirectory()).toBe(true);
}));
});
});
describe('.rmdir()', () => {
test('can remove an empty folder', () => __awaiter(void 0, void 0, void 0, function* () {
const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null });
yield fs.promises.rmdir('/empty-folder');
expect(mfs.__vol.toJSON()).toStrictEqual({ '/mountpoint/folder/file': 'test' });
}));
test('throws when attempts to remove non-empty folder', () => __awaiter(void 0, void 0, void 0, function* () {
const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null });
test('can remove an empty folder', async () => {
const { fs, vol } = setup({ folder: { file: 'test' }, 'empty-folder': null });
await fs.promises.rmdir('/empty-folder');
expect(vol.toJSON()).toStrictEqual({ '/mountpoint/folder/file': 'test' });
});
test('throws when attempts to remove non-empty folder', async () => {
const { fs, vol } = setup({ folder: { file: 'test' }, 'empty-folder': null });
try {
yield fs.promises.rmdir('/folder');
await fs.promises.rmdir('/folder');
throw new Error('Expected error');

@@ -100,3 +100,3 @@ }

expect(error.code).toBe('ENOTEMPTY');
expect(mfs.__vol.toJSON()).toStrictEqual({
expect(vol.toJSON()).toStrictEqual({
'/mountpoint/folder/file': 'test',

@@ -106,28 +106,28 @@ '/mountpoint/empty-folder': null,

}
}));
test('can remove non-empty directory recursively', () => __awaiter(void 0, void 0, void 0, function* () {
const { fs, mfs } = setup({ folder: { subfolder: { file: 'test' } }, 'empty-folder': null });
yield fs.promises.rmdir('/folder', { recursive: true });
expect(mfs.__vol.toJSON()).toStrictEqual({
});
test('can remove non-empty directory recursively', async () => {
const { fs, vol } = setup({ folder: { subfolder: { file: 'test' } }, 'empty-folder': null });
await fs.promises.rmdir('/folder', { recursive: true });
expect(vol.toJSON()).toStrictEqual({
'/mountpoint/empty-folder': null,
});
}));
test('can remove starting from root folder', () => __awaiter(void 0, void 0, void 0, function* () {
const { fs, mfs } = setup({ folder: { subfolder: { file: 'test' } }, 'empty-folder': null });
yield fs.promises.rmdir('/', { recursive: true });
expect(mfs.__vol.toJSON()).toStrictEqual({
});
test('can remove starting from root folder', async () => {
const { fs, vol } = setup({ folder: { subfolder: { file: 'test' } }, 'empty-folder': null });
await fs.promises.rmdir('/', { recursive: true });
expect(vol.toJSON()).toStrictEqual({
'/mountpoint': null,
});
}));
});
});
describe('.rm()', () => {
test('can remove an empty folder', () => __awaiter(void 0, void 0, void 0, function* () {
const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null });
yield fs.promises.rm('/empty-folder');
expect(mfs.__vol.toJSON()).toStrictEqual({ '/mountpoint/folder/file': 'test' });
}));
test('throws when attempts to remove non-empty folder', () => __awaiter(void 0, void 0, void 0, function* () {
const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null });
test('can remove an empty folder', async () => {
const { fs, vol } = setup({ folder: { file: 'test' }, 'empty-folder': null });
await fs.promises.rm('/empty-folder');
expect(vol.toJSON()).toStrictEqual({ '/mountpoint/folder/file': 'test' });
});
test('throws when attempts to remove non-empty folder', async () => {
const { fs, vol } = setup({ folder: { file: 'test' }, 'empty-folder': null });
try {
yield fs.promises.rm('/folder');
await fs.promises.rm('/folder');
throw new Error('Expected error');

@@ -137,3 +137,3 @@ }

expect(error.code).toBe('ENOTEMPTY');
expect(mfs.__vol.toJSON()).toStrictEqual({
expect(vol.toJSON()).toStrictEqual({
'/mountpoint/folder/file': 'test',

@@ -143,14 +143,14 @@ '/mountpoint/empty-folder': null,

}
}));
test('can remove non-empty directory recursively', () => __awaiter(void 0, void 0, void 0, function* () {
const { fs, mfs } = setup({ folder: { subfolder: { file: 'test' } }, 'empty-folder': null });
yield fs.promises.rm('/folder', { recursive: true });
expect(mfs.__vol.toJSON()).toStrictEqual({
});
test('can remove non-empty directory recursively', async () => {
const { fs, vol } = setup({ folder: { subfolder: { file: 'test' } }, 'empty-folder': null });
await fs.promises.rm('/folder', { recursive: true });
expect(vol.toJSON()).toStrictEqual({
'/mountpoint/empty-folder': null,
});
}));
test('throws if path does not exist', () => __awaiter(void 0, void 0, void 0, function* () {
const { fs, mfs } = setup({ folder: { subfolder: { file: 'test' } }, 'empty-folder': null });
});
test('throws if path does not exist', async () => {
const { fs, vol } = setup({ folder: { subfolder: { file: 'test' } }, 'empty-folder': null });
try {
yield fs.promises.rm('/lala/lulu', { recursive: true });
await fs.promises.rm('/lala/lulu', { recursive: true });
throw new Error('Expected error');

@@ -160,3 +160,3 @@ }

expect(error.code).toBe('ENOENT');
expect(mfs.__vol.toJSON()).toStrictEqual({
expect(vol.toJSON()).toStrictEqual({
'/mountpoint/folder/subfolder/file': 'test',

@@ -166,37 +166,37 @@ '/mountpoint/empty-folder': null,

}
}));
test('does not throw, if path does not exist, but "force" flag set', () => __awaiter(void 0, void 0, void 0, function* () {
const { fs } = setup({ folder: { subfolder: { file: 'test' } }, 'empty-folder': null });
yield fs.promises.rm('/lala/lulu', { recursive: true, force: true });
}));
test('can remove a file', () => __awaiter(void 0, void 0, void 0, function* () {
const { fs, mfs } = setup({ folder: { subfolder: { file: 'test' } }, 'empty-folder': null });
yield fs.promises.rm('/folder/subfolder/file');
expect(mfs.__vol.toJSON()).toStrictEqual({
});
test('does not throw, if path does not exist, but "force" flag set', async () => {
const { fs, vol } = setup({ folder: { subfolder: { file: 'test' } }, 'empty-folder': null });
await fs.promises.rm('/lala/lulu', { recursive: true, force: true });
});
test('can remove a file', async () => {
const { fs, vol } = setup({ folder: { subfolder: { file: 'test' } }, 'empty-folder': null });
await fs.promises.rm('/folder/subfolder/file');
expect(vol.toJSON()).toStrictEqual({
'/mountpoint/folder/subfolder': null,
'/mountpoint/empty-folder': null,
});
}));
test('can remove starting from root folder', () => __awaiter(void 0, void 0, void 0, function* () {
const { fs, mfs } = setup({ folder: { subfolder: { file: 'test' } }, 'empty-folder': null });
yield fs.promises.rm('/', { recursive: true });
expect(mfs.__vol.toJSON()).toStrictEqual({
});
test('can remove starting from root folder', async () => {
const { fs, vol } = setup({ folder: { subfolder: { file: 'test' } }, 'empty-folder': null });
await fs.promises.rm('/', { recursive: true });
expect(vol.toJSON()).toStrictEqual({
'/mountpoint': null,
});
}));
});
});
describe('.unlink()', () => {
test('can remove a file', () => __awaiter(void 0, void 0, void 0, function* () {
const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null });
const res = yield fs.promises.unlink('/folder/file');
test('can remove a file', async () => {
const { fs, vol } = setup({ folder: { file: 'test' }, 'empty-folder': null });
const res = await fs.promises.unlink('/folder/file');
expect(res).toBe(undefined);
expect(mfs.__vol.toJSON()).toStrictEqual({
expect(vol.toJSON()).toStrictEqual({
'/mountpoint/folder': null,
'/mountpoint/empty-folder': null,
});
}));
test('cannot delete a folder', () => __awaiter(void 0, void 0, void 0, function* () {
const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null });
});
test('cannot delete a folder', async () => {
const { fs, vol } = setup({ folder: { file: 'test' }, 'empty-folder': null });
try {
yield fs.promises.unlink('/folder');
await fs.promises.unlink('/folder');
throw new Error('Expected error');

@@ -206,3 +206,3 @@ }

expect(error.code).toBe('EISDIR');
expect(mfs.__vol.toJSON()).toStrictEqual({
expect(vol.toJSON()).toStrictEqual({
'/mountpoint/folder/file': 'test',

@@ -212,7 +212,7 @@ '/mountpoint/empty-folder': null,

}
}));
test('throws when deleting non-existing file', () => __awaiter(void 0, void 0, void 0, function* () {
const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null });
});
test('throws when deleting non-existing file', async () => {
const { fs, vol } = setup({ folder: { file: 'test' }, 'empty-folder': null });
try {
yield fs.promises.unlink('/folder/not-a-file');
await fs.promises.unlink('/folder/not-a-file');
throw new Error('Expected error');

@@ -222,3 +222,3 @@ }

expect(error.code).toBe('ENOENT');
expect(mfs.__vol.toJSON()).toStrictEqual({
expect(vol.toJSON()).toStrictEqual({
'/mountpoint/folder/file': 'test',

@@ -228,39 +228,39 @@ '/mountpoint/empty-folder': null,

}
}));
});
});
describe('.readFile()', () => {
test('can read file contents', () => __awaiter(void 0, void 0, void 0, function* () {
test('can read file contents', async () => {
const { fs } = setup({ folder: { file: 'test' }, 'empty-folder': null });
const data = yield fs.promises.readFile('/folder/file');
const data = await fs.promises.readFile('/folder/file');
expect(data.toString()).toBe('test');
}));
test('can read file by file handle', () => __awaiter(void 0, void 0, void 0, function* () {
});
test('can read file by file handle', async () => {
const { fs } = setup({ folder: { file: 'test' }, 'empty-folder': null });
const handle = yield fs.promises.open('/folder/file');
const handle = await fs.promises.open('/folder/file');
expect(typeof handle).toBe('object');
const data = yield fs.promises.readFile(handle);
const data = await fs.promises.readFile(handle);
expect(data.toString()).toBe('test');
}));
test('can read file by file descriptor', () => __awaiter(void 0, void 0, void 0, function* () {
});
test('can read file by file descriptor', async () => {
const { fs } = setup({ folder: { file: 'test' }, 'empty-folder': null });
const fd = yield new Promise(resolve => {
const fd = await new Promise(resolve => {
fs.open('/folder/file', 'r', (err, fd) => resolve(fd));
});
expect(typeof fd).toBe('number');
const data = yield new Promise(resolve => {
const data = await new Promise(resolve => {
fs.readFile(fd, { encoding: 'utf8' }, (err, data) => resolve(data));
});
expect(data).toBe('test');
}));
test('cannot read from closed file descriptor', () => __awaiter(void 0, void 0, void 0, function* () {
});
test('cannot read from closed file descriptor', async () => {
const { fs } = setup({ folder: { file: 'test' }, 'empty-folder': null });
const fd = yield new Promise(resolve => {
const fd = await new Promise(resolve => {
fs.open('/folder/file', 'r', (err, fd) => resolve(fd));
});
expect(typeof fd).toBe('number');
yield new Promise(resolve => {
await new Promise(resolve => {
fs.close(fd, () => resolve());
});
try {
yield new Promise((resolve, reject) => {
await new Promise((resolve, reject) => {
fs.readFile(fd, { encoding: 'utf8' }, (err, data) => reject(err));

@@ -274,8 +274,8 @@ });

}
}));
});
});
describe('.truncate()', () => {
test('can truncate a file', () => __awaiter(void 0, void 0, void 0, function* () {
test('can truncate a file', async () => {
const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null });
const res = yield new Promise((resolve, reject) => {
const res = await new Promise((resolve, reject) => {
fs.truncate('/folder/file', 2, (err, res) => (err ? reject(err) : resolve(res)));

@@ -285,9 +285,9 @@ });

expect(mfs.readFileSync('/mountpoint/folder/file', 'utf8')).toBe('te');
}));
});
});
describe('.ftruncate()', () => {
test('can truncate a file', () => __awaiter(void 0, void 0, void 0, function* () {
test('can truncate a file', async () => {
const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null });
const handle = yield fs.promises.open('/folder/file');
const res = yield new Promise((resolve, reject) => {
const handle = await fs.promises.open('/folder/file');
const res = await new Promise((resolve, reject) => {
fs.ftruncate(handle.fd, 3, (err, res) => (err ? reject(err) : resolve(res)));

@@ -297,8 +297,8 @@ });

expect(mfs.readFileSync('/mountpoint/folder/file', 'utf8')).toBe('tes');
}));
});
});
describe('.readdir()', () => {
test('can read directory contents as strings', () => __awaiter(void 0, void 0, void 0, function* () {
test('can read directory contents as strings', async () => {
const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' });
const res = (yield fs.promises.readdir('/'));
const res = (await fs.promises.readdir('/'));
expect(res.length).toBe(3);

@@ -308,7 +308,7 @@ expect(res.includes('folder')).toBe(true);

expect(res.includes('f.html')).toBe(true);
}));
test('can read directory contents with "withFileTypes" flag set', () => __awaiter(void 0, void 0, void 0, function* () {
});
test('can read directory contents with "withFileTypes" flag set', async () => {
var _a, _b, _c, _d;
const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' });
const list = (yield fs.promises.readdir('/', { withFileTypes: true }));
const list = (await fs.promises.readdir('/', { withFileTypes: true }));
expect(list.length).toBe(3);

@@ -321,32 +321,32 @@ const names = list.map(item => item.name);

expect((_d = list.find(item => item.name === 'f.html')) === null || _d === void 0 ? void 0 : _d.isDirectory()).toBe(false);
}));
});
});
describe('.appendFile()', () => {
test('can create a file', () => __awaiter(void 0, void 0, void 0, function* () {
test('can create a file', async () => {
const { fs, mfs } = setup({});
yield fs.promises.appendFile('/test.txt', 'a');
await fs.promises.appendFile('/test.txt', 'a');
expect(mfs.readFileSync('/mountpoint/test.txt', 'utf8')).toBe('a');
}));
test('can append to a file', () => __awaiter(void 0, void 0, void 0, function* () {
});
test('can append to a file', async () => {
const { fs, mfs } = setup({});
yield fs.promises.appendFile('/test.txt', 'a');
yield fs.promises.appendFile('/test.txt', 'b');
await fs.promises.appendFile('/test.txt', 'a');
await fs.promises.appendFile('/test.txt', 'b');
expect(mfs.readFileSync('/mountpoint/test.txt', 'utf8')).toBe('ab');
}));
test('can append to a file - 2', () => __awaiter(void 0, void 0, void 0, function* () {
});
test('can append to a file - 2', async () => {
const { fs, mfs } = setup({ file: '123' });
yield fs.promises.appendFile('file', 'x');
await fs.promises.appendFile('file', 'x');
expect(mfs.readFileSync('/mountpoint/file', 'utf8')).toBe('123x');
}));
test('can append to a file - 2', () => __awaiter(void 0, void 0, void 0, function* () {
});
test('can append to a file - 2', async () => {
const { fs, mfs } = setup({ file: '123' });
yield fs.promises.writeFile('cool.txt', 'worlds');
yield fs.promises.appendFile('cool.txt', '!');
await fs.promises.writeFile('cool.txt', 'worlds');
await fs.promises.appendFile('cool.txt', '!');
expect(mfs.readFileSync('/mountpoint/cool.txt', 'utf8')).toBe('worlds!');
}));
});
});
describe('.write()', () => {
test('can write to a file', () => __awaiter(void 0, void 0, void 0, function* () {
test('can write to a file', async () => {
const { fs, mfs } = setup({});
const fd = yield new Promise((resolve, reject) => fs.open('/test.txt', 'w', (err, fd) => {
const fd = await new Promise((resolve, reject) => fs.open('/test.txt', 'w', (err, fd) => {
if (err)

@@ -357,3 +357,3 @@ reject(err);

}));
const [bytesWritten, data] = yield new Promise((resolve, reject) => {
const [bytesWritten, data] = await new Promise((resolve, reject) => {
fs.write(fd, 'a', (err, bytesWritten, data) => {

@@ -369,6 +369,6 @@ if (err)

expect(mfs.readFileSync('/mountpoint/test.txt', 'utf8')).toBe('a');
}));
test('can write to a file twice sequentially', () => __awaiter(void 0, void 0, void 0, function* () {
});
test('can write to a file twice sequentially', async () => {
const { fs, mfs } = setup({});
const fd = yield new Promise((resolve, reject) => fs.open('/test.txt', 'w', (err, fd) => {
const fd = await new Promise((resolve, reject) => fs.open('/test.txt', 'w', (err, fd) => {
if (err)

@@ -379,3 +379,3 @@ reject(err);

}));
const res1 = yield new Promise((resolve, reject) => {
const res1 = await new Promise((resolve, reject) => {
fs.write(fd, 'a', (err, bytesWritten, data) => {

@@ -390,3 +390,3 @@ if (err)

expect(res1[1]).toBe('a');
const res2 = yield new Promise((resolve, reject) => {
const res2 = await new Promise((resolve, reject) => {
fs.write(fd, 'bc', (err, bytesWritten, data) => {

@@ -402,8 +402,8 @@ if (err)

expect(mfs.readFileSync('/mountpoint/test.txt', 'utf8')).toBe('abc');
}));
});
});
describe('.writev()', () => {
test('can write to a file two buffers', () => __awaiter(void 0, void 0, void 0, function* () {
test('can write to a file two buffers', async () => {
const { fs, mfs } = setup({});
const fd = yield new Promise((resolve, reject) => fs.open('/test.txt', 'w', (err, fd) => {
const fd = await new Promise((resolve, reject) => fs.open('/test.txt', 'w', (err, fd) => {
if (err)

@@ -414,3 +414,3 @@ reject(err);

}));
const [bytesWritten, data] = yield new Promise((resolve, reject) => {
const [bytesWritten, data] = await new Promise((resolve, reject) => {
const buffers = [Buffer.from('a'), Buffer.from('b')];

@@ -426,40 +426,40 @@ fs.writev(fd, buffers, (err, bytesWritten, data) => {

expect(mfs.readFileSync('/mountpoint/test.txt', 'utf8')).toBe('ab');
}));
});
});
describe('.exists()', () => {
test('can works for folders and files', () => __awaiter(void 0, void 0, void 0, function* () {
test('can works for folders and files', async () => {
const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' });
const exists = (path) => __awaiter(void 0, void 0, void 0, function* () {
const exists = async (path) => {
return new Promise(resolve => {
fs.exists(path, exists => resolve(exists));
});
});
expect(yield exists('/folder')).toBe(true);
expect(yield exists('/folder/file')).toBe(true);
expect(yield exists('/folder/not-a-file')).toBe(false);
expect(yield exists('/f.html')).toBe(true);
expect(yield exists('/empty-folder')).toBe(true);
expect(yield exists('/')).toBe(true);
expect(yield exists('/asdf')).toBe(false);
expect(yield exists('asdf')).toBe(false);
}));
};
expect(await exists('/folder')).toBe(true);
expect(await exists('/folder/file')).toBe(true);
expect(await exists('/folder/not-a-file')).toBe(false);
expect(await exists('/f.html')).toBe(true);
expect(await exists('/empty-folder')).toBe(true);
expect(await exists('/')).toBe(true);
expect(await exists('/asdf')).toBe(false);
expect(await exists('asdf')).toBe(false);
});
});
describe('.access()', () => {
describe('files', () => {
test('succeeds on file existence check', () => __awaiter(void 0, void 0, void 0, function* () {
test('succeeds on file existence check', async () => {
const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' });
yield fs.promises.access('/folder/file', 0 /* AMODE.F_OK */);
}));
test('succeeds on file "read" check', () => __awaiter(void 0, void 0, void 0, function* () {
await fs.promises.access('/folder/file', 0 /* AMODE.F_OK */);
});
test('succeeds on file "read" check', async () => {
const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' });
yield fs.promises.access('/folder/file', 4 /* AMODE.R_OK */);
}));
test('succeeds on file "write" check, on writable file system', () => __awaiter(void 0, void 0, void 0, function* () {
await fs.promises.access('/folder/file', 4 /* AMODE.R_OK */);
});
test('succeeds on file "write" check, on writable file system', async () => {
const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' });
yield fs.promises.access('/folder/file', 2 /* AMODE.W_OK */);
}));
test('fails on file "write" check, on read-only file system', () => __awaiter(void 0, void 0, void 0, function* () {
await fs.promises.access('/folder/file', 2 /* AMODE.W_OK */);
});
test('fails on file "write" check, on read-only file system', async () => {
const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' }, 'read');
try {
yield fs.promises.access('/folder/file', 2 /* AMODE.W_OK */);
await fs.promises.access('/folder/file', 2 /* AMODE.W_OK */);
throw new Error('should not be here');

@@ -470,7 +470,7 @@ }

}
}));
test('fails on file "execute" check', () => __awaiter(void 0, void 0, void 0, function* () {
});
test('fails on file "execute" check', async () => {
const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' });
try {
yield fs.promises.access('/folder/file', 1 /* AMODE.X_OK */);
await fs.promises.access('/folder/file', 1 /* AMODE.X_OK */);
throw new Error('should not be here');

@@ -481,21 +481,21 @@ }

}
}));
});
});
describe('directories', () => {
test('succeeds on folder existence check', () => __awaiter(void 0, void 0, void 0, function* () {
test('succeeds on folder existence check', async () => {
const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' });
yield fs.promises.access('/folder', 0 /* AMODE.F_OK */);
}));
test('succeeds on folder "read" check', () => __awaiter(void 0, void 0, void 0, function* () {
await fs.promises.access('/folder', 0 /* AMODE.F_OK */);
});
test('succeeds on folder "read" check', async () => {
const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' });
yield fs.promises.access('/folder', 4 /* AMODE.R_OK */);
}));
test('succeeds on folder "write" check, on writable file system', () => __awaiter(void 0, void 0, void 0, function* () {
await fs.promises.access('/folder', 4 /* AMODE.R_OK */);
});
test('succeeds on folder "write" check, on writable file system', async () => {
const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' });
yield fs.promises.access('/folder', 2 /* AMODE.W_OK */);
}));
test('fails on folder "write" check, on read-only file system', () => __awaiter(void 0, void 0, void 0, function* () {
await fs.promises.access('/folder', 2 /* AMODE.W_OK */);
});
test('fails on folder "write" check, on read-only file system', async () => {
const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' }, 'read');
try {
yield fs.promises.access('/folder', 2 /* AMODE.W_OK */);
await fs.promises.access('/folder', 2 /* AMODE.W_OK */);
throw new Error('should not be here');

@@ -506,7 +506,7 @@ }

}
}));
test('fails on folder "execute" check', () => __awaiter(void 0, void 0, void 0, function* () {
});
test('fails on folder "execute" check', async () => {
const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' });
try {
yield fs.promises.access('/folder', 1 /* AMODE.X_OK */);
await fs.promises.access('/folder', 1 /* AMODE.X_OK */);
throw new Error('should not be here');

@@ -517,10 +517,10 @@ }

}
}));
});
});
});
describe('.rename()', () => {
test('can rename a file', () => __awaiter(void 0, void 0, void 0, function* () {
const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' });
yield fs.promises.rename('/folder/file', '/folder/file2');
expect(mfs.__vol.toJSON()).toStrictEqual({
test('can rename a file', async () => {
const { fs, mfs, vol } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' });
await fs.promises.rename('/folder/file', '/folder/file2');
expect(vol.toJSON()).toStrictEqual({
'/mountpoint/folder/file2': 'test',

@@ -530,35 +530,35 @@ '/mountpoint/empty-folder': null,

});
}));
});
});
describe('.stat()', () => {
test('can stat a file', () => __awaiter(void 0, void 0, void 0, function* () {
test('can stat a file', async () => {
const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' });
const stats = yield fs.promises.stat('/folder/file');
const stats = await fs.promises.stat('/folder/file');
expect(stats.isFile()).toBe(true);
}));
test('throws "ENOENT" when path is not found', () => __awaiter(void 0, void 0, void 0, function* () {
});
test('throws "ENOENT" when path is not found', async () => {
const { fs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' });
const [, error] = yield (0, thingies_1.of)(fs.promises.stat('/folder/repo/.git'));
const [, error] = await (0, thingies_1.of)(fs.promises.stat('/folder/repo/.git'));
expect(error.code).toBe('ENOENT');
}));
test('throws "ENOTDIR" when sub-folder is a file', () => __awaiter(void 0, void 0, void 0, function* () {
});
test('throws "ENOTDIR" when sub-folder is a file', async () => {
const { fs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' });
const [, error] = yield (0, thingies_1.of)(fs.promises.stat('/folder/file/repo/.git'));
const [, error] = await (0, thingies_1.of)(fs.promises.stat('/folder/file/repo/.git'));
expect(error.code).toBe('ENOTDIR');
}));
test('can retrieve file size', () => __awaiter(void 0, void 0, void 0, function* () {
});
test('can retrieve file size', async () => {
const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' });
const stats = yield fs.promises.stat('/folder/file');
const stats = await fs.promises.stat('/folder/file');
expect(stats.size).toBe(4);
}));
test('can stat a folder', () => __awaiter(void 0, void 0, void 0, function* () {
});
test('can stat a folder', async () => {
const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' });
const stats = yield fs.promises.stat('/folder');
const stats = await fs.promises.stat('/folder');
expect(stats.isFile()).toBe(false);
expect(stats.isDirectory()).toBe(true);
}));
test('throws on non-existing path', () => __awaiter(void 0, void 0, void 0, function* () {
});
test('throws on non-existing path', async () => {
const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' });
try {
const stats = yield fs.promises.stat('/folder/abc');
const stats = await fs.promises.stat('/folder/abc');
throw new Error('should not be here');

@@ -569,25 +569,25 @@ }

}
}));
});
});
describe('.lstat()', () => {
test('can stat a file', () => __awaiter(void 0, void 0, void 0, function* () {
test('can stat a file', async () => {
const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' });
const stats = yield fs.promises.lstat('/folder/file');
const stats = await fs.promises.lstat('/folder/file');
expect(stats.isFile()).toBe(true);
}));
test('can retrieve file size', () => __awaiter(void 0, void 0, void 0, function* () {
});
test('can retrieve file size', async () => {
const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' });
const stats = yield fs.promises.lstat('/folder/file');
const stats = await fs.promises.lstat('/folder/file');
expect(stats.size).toBe(4);
}));
test('can stat a folder', () => __awaiter(void 0, void 0, void 0, function* () {
});
test('can stat a folder', async () => {
const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' });
const stats = yield fs.promises.lstat('/folder');
const stats = await fs.promises.lstat('/folder');
expect(stats.isFile()).toBe(false);
expect(stats.isDirectory()).toBe(true);
}));
test('throws on non-existing path', () => __awaiter(void 0, void 0, void 0, function* () {
});
test('throws on non-existing path', async () => {
const { fs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' });
try {
yield fs.promises.lstat('/folder/abc');
await fs.promises.lstat('/folder/abc');
throw new Error('should not be here');

@@ -598,9 +598,9 @@ }

}
}));
});
});
describe('.fstat()', () => {
test('can stat a file', () => __awaiter(void 0, void 0, void 0, function* () {
test('can stat a file', async () => {
const { fs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' });
const handle = yield fs.promises.open('/folder/file', 'r');
const stats = yield new Promise((resolve, reject) => {
const handle = await fs.promises.open('/folder/file', 'r');
const stats = await new Promise((resolve, reject) => {
fs.fstat(handle.fd, (error, stats) => {

@@ -614,23 +614,23 @@ if (error)

expect(stats.isFile()).toBe(true);
}));
});
});
describe('.realpath()', () => {
test('returns file path', () => __awaiter(void 0, void 0, void 0, function* () {
test('returns file path', async () => {
const { fs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' });
const path = yield fs.promises.realpath('folder/file');
const path = await fs.promises.realpath('folder/file');
expect(path).toBe('/folder/file');
}));
});
});
describe('.realpathSync()', () => {
test('returns file path', () => __awaiter(void 0, void 0, void 0, function* () {
test('returns file path', async () => {
const { fs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' });
const path = fs.realpathSync('folder/file');
expect(path).toBe('/folder/file');
}));
});
});
describe('.copyFile()', () => {
test('can copy a file', () => __awaiter(void 0, void 0, void 0, function* () {
const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' });
yield fs.promises.copyFile('/folder/file', '/folder/file2');
expect(mfs.__vol.toJSON()).toStrictEqual({
test('can copy a file', async () => {
const { fs, vol } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' });
await fs.promises.copyFile('/folder/file', '/folder/file2');
expect(vol.toJSON()).toStrictEqual({
'/mountpoint/folder/file': 'test',

@@ -641,8 +641,8 @@ '/mountpoint/folder/file2': 'test',

});
}));
});
});
describe('.writeFile()', () => {
test('can create a new file', () => __awaiter(void 0, void 0, void 0, function* () {
const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' });
const res = yield new Promise((resolve, reject) => {
test('can create a new file', async () => {
const { fs, vol } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' });
const res = await new Promise((resolve, reject) => {
fs.writeFile('/folder/foo', 'bar', error => {

@@ -656,3 +656,3 @@ if (error)

expect(res).toBe(undefined);
expect(mfs.__vol.toJSON()).toStrictEqual({
expect(vol.toJSON()).toStrictEqual({
'/mountpoint/folder/file': 'test',

@@ -663,9 +663,21 @@ '/mountpoint/folder/foo': 'bar',

});
}));
});
test('throws "EEXIST", if file already exists and O_EXCL flag set', async () => {
const { fs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' });
const [, err] = await (0, thingies_1.of)(fs.promises.writeFile('/folder/file', 'bar', { flag: 'wx' }));
expect(err).toBeInstanceOf(Error);
expect(err.code).toBe('EEXIST');
});
test('throws "ENOENT", if file does not exist and O_CREAT flag not set', async () => {
const { fs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' });
const [, err] = await (0, thingies_1.of)(fs.promises.writeFile('/folder/file2', 'bar', { flag: 2 /* FLAG.O_RDWR */ }));
expect(err).toBeInstanceOf(Error);
expect(err.code).toBe('ENOENT');
});
});
describe('.read()', () => {
test('can read from a file at offset into Buffer', () => __awaiter(void 0, void 0, void 0, function* () {
test('can read from a file at offset into Buffer', async () => {
const { fs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' });
const handle = yield fs.promises.open('/folder/file', 'r');
const [buffer, length] = yield new Promise((resolve, reject) => {
const handle = await fs.promises.open('/folder/file', 'r');
const [buffer, length] = await new Promise((resolve, reject) => {
const buffer = Buffer.alloc(4);

@@ -681,7 +693,7 @@ fs.read(handle.fd, buffer, 0, 2, 1, (error, bytesRead, buffer) => {

expect(buffer.slice(0, 2).toString()).toBe('es');
}));
test('can read from a file at offset into Uint8Array', () => __awaiter(void 0, void 0, void 0, function* () {
});
test('can read from a file at offset into Uint8Array', async () => {
const { fs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' });
const handle = yield fs.promises.open('/folder/file', 'r');
const [buffer, length] = yield new Promise((resolve, reject) => {
const handle = await fs.promises.open('/folder/file', 'r');
const [buffer, length] = await new Promise((resolve, reject) => {
const buffer = new Uint8Array(4);

@@ -698,7 +710,7 @@ fs.read(handle.fd, buffer, 0, 2, 1, (error, bytesRead, buffer) => {

expect(buffer[1]).toBe(115);
}));
});
});
describe('.createWriteStream()', () => {
test('can use stream to write to a new file', () => __awaiter(void 0, void 0, void 0, function* () {
const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' });
test('can use stream to write to a new file', async () => {
const { fs, vol } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' });
const stream = fs.createWriteStream('/folder/file2');

@@ -709,5 +721,5 @@ stream.write(Buffer.from('A'));

stream.end();
yield new Promise(resolve => stream.once('close', resolve));
await new Promise(resolve => stream.once('close', resolve));
expect(stream.bytesWritten).toBe(6);
expect(mfs.__vol.toJSON()).toStrictEqual({
expect(vol.toJSON()).toStrictEqual({
'/mountpoint/folder/file': 'test',

@@ -718,5 +730,5 @@ '/mountpoint/folder/file2': 'ABCDEF',

});
}));
test('can use stream to write to a new file using strings', () => __awaiter(void 0, void 0, void 0, function* () {
const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' });
});
test('can use stream to write to a new file using strings', async () => {
const { fs, vol } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' });
const stream = fs.createWriteStream('/folder/file2');

@@ -727,5 +739,5 @@ stream.write('A');

stream.end();
yield new Promise(resolve => stream.once('close', resolve));
await new Promise(resolve => stream.once('close', resolve));
expect(stream.bytesWritten).toBe(6);
expect(mfs.__vol.toJSON()).toStrictEqual({
expect(vol.toJSON()).toStrictEqual({
'/mountpoint/folder/file': 'test',

@@ -736,5 +748,5 @@ '/mountpoint/folder/file2': 'ABCDEF',

});
}));
test('can use stream to overwrite existing file', () => __awaiter(void 0, void 0, void 0, function* () {
const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' });
});
test('can use stream to overwrite existing file', async () => {
const { fs, vol } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' });
const stream = fs.createWriteStream('/folder/file');

@@ -744,5 +756,5 @@ stream.write(Buffer.from('A'));

stream.end();
yield new Promise(resolve => stream.once('close', resolve));
await new Promise(resolve => stream.once('close', resolve));
expect(stream.bytesWritten).toBe(3);
expect(mfs.__vol.toJSON()).toStrictEqual({
expect(vol.toJSON()).toStrictEqual({
'/mountpoint/folder/file': 'ABC',

@@ -752,12 +764,12 @@ '/mountpoint/empty-folder': null,

});
}));
test('can write by file descriptor', () => __awaiter(void 0, void 0, void 0, function* () {
const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' });
const handle = yield fs.promises.open('/folder/file', 'a');
});
test('can write by file descriptor', async () => {
const { fs, mfs, vol } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' });
const handle = await fs.promises.open('/folder/file', 'a');
const stream = fs.createWriteStream('', { fd: handle.fd, start: 1, flags: 'a' });
stream.write(Buffer.from('BC'));
stream.end();
yield new Promise(resolve => stream.once('close', resolve));
await new Promise(resolve => stream.once('close', resolve));
expect(stream.bytesWritten).toBe(2);
expect(mfs.__vol.toJSON()).toStrictEqual({
expect(vol.toJSON()).toStrictEqual({
'/mountpoint/folder/file': 'tBCt',

@@ -767,45 +779,41 @@ '/mountpoint/empty-folder': null,

});
}));
test('closes file once stream ends', () => __awaiter(void 0, void 0, void 0, function* () {
});
test('closes file once stream ends', async () => {
const { fs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' });
const handle = yield fs.promises.open('/folder/file', 'a');
const handle = await fs.promises.open('/folder/file', 'a');
const stream = fs.createWriteStream('', { fd: handle.fd, start: 1, flags: 'a' });
stream.write(Buffer.from('BC'));
const stat = () => __awaiter(void 0, void 0, void 0, function* () {
return yield new Promise((resolve, reject) => fs.fstat(handle.fd, (err, stats) => {
if (err)
reject(err);
else
resolve(stats);
}));
});
yield stat();
const stat = async () => await new Promise((resolve, reject) => fs.fstat(handle.fd, (err, stats) => {
if (err)
reject(err);
else
resolve(stats);
}));
await stat();
stream.end();
yield (0, thingies_1.until)(() => __awaiter(void 0, void 0, void 0, function* () {
const [, error] = yield (0, thingies_1.of)(stat());
await (0, thingies_1.until)(async () => {
const [, error] = await (0, thingies_1.of)(stat());
return !!error;
}));
const [, error] = yield (0, thingies_1.of)(stat());
});
const [, error] = await (0, thingies_1.of)(stat());
expect(error.code).toBe('EBADF');
}));
test('does not close file if "autoClose" is false', () => __awaiter(void 0, void 0, void 0, function* () {
});
test('does not close file if "autoClose" is false', async () => {
const { fs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' });
const handle = yield fs.promises.open('/folder/file', 'a');
const handle = await fs.promises.open('/folder/file', 'a');
const stream = fs.createWriteStream('', { fd: handle.fd, start: 1, flags: 'a', autoClose: false });
stream.write(Buffer.from('BC'));
const stat = () => __awaiter(void 0, void 0, void 0, function* () {
return yield new Promise((resolve, reject) => fs.fstat(handle.fd, (err, stats) => {
if (err)
reject(err);
else
resolve(stats);
}));
});
yield stat();
const stat = async () => await new Promise((resolve, reject) => fs.fstat(handle.fd, (err, stats) => {
if (err)
reject(err);
else
resolve(stats);
}));
await stat();
stream.end();
yield (0, thingies_1.tick)(200);
yield stat();
}));
test('can use stream to add to existing file', () => __awaiter(void 0, void 0, void 0, function* () {
const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' });
await (0, thingies_1.tick)(200);
await stat();
});
test('can use stream to add to existing file', async () => {
const { fs, vol } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' });
const stream = fs.createWriteStream('/folder/file', { flags: 'a' });

@@ -815,5 +823,5 @@ stream.write(Buffer.from('A'));

stream.end();
yield new Promise(resolve => stream.once('close', resolve));
await new Promise(resolve => stream.once('close', resolve));
expect(stream.bytesWritten).toBe(3);
expect(mfs.__vol.toJSON()).toStrictEqual({
expect(vol.toJSON()).toStrictEqual({
'/mountpoint/folder/file': 'ABCt',

@@ -823,5 +831,5 @@ '/mountpoint/empty-folder': null,

});
}));
test('can use stream to add to existing file at specified offset', () => __awaiter(void 0, void 0, void 0, function* () {
const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' });
});
test('can use stream to add to existing file at specified offset', async () => {
const { fs, vol } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' });
const stream = fs.createWriteStream('/folder/file', { flags: 'a', start: 1 });

@@ -831,5 +839,5 @@ stream.write(Buffer.from('A'));

stream.end();
yield new Promise(resolve => stream.once('close', resolve));
await new Promise(resolve => stream.once('close', resolve));
expect(stream.bytesWritten).toBe(2);
expect(mfs.__vol.toJSON()).toStrictEqual({
expect(vol.toJSON()).toStrictEqual({
'/mountpoint/folder/file': 'tABt',

@@ -839,4 +847,4 @@ '/mountpoint/empty-folder': null,

});
}));
test('throws if "start" option is not a number', () => __awaiter(void 0, void 0, void 0, function* () {
});
test('throws if "start" option is not a number', async () => {
const { fs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' });

@@ -851,4 +859,4 @@ try {

}
}));
test('throws if "start" option is negative', () => __awaiter(void 0, void 0, void 0, function* () {
});
test('throws if "start" option is negative', async () => {
const { fs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' });

@@ -863,12 +871,12 @@ try {

}
}));
});
});
describe('.createReadStream()', () => {
test('can pipe fs.ReadStream to fs.WriteStream', () => __awaiter(void 0, void 0, void 0, function* () {
const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' });
test('can pipe fs.ReadStream to fs.WriteStream', async () => {
const { fs, vol } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' });
const readStream = fs.createReadStream('/folder/file');
const writeStream = fs.createWriteStream('/folder/file2');
readStream.pipe(writeStream);
yield new Promise(resolve => writeStream.once('close', resolve));
expect(mfs.__vol.toJSON()).toStrictEqual({
await new Promise(resolve => writeStream.once('close', resolve));
expect(vol.toJSON()).toStrictEqual({
'/mountpoint/folder/file': 'test',

@@ -879,15 +887,15 @@ '/mountpoint/folder/file2': 'test',

});
}));
test('emits "open" event', () => __awaiter(void 0, void 0, void 0, function* () {
});
test('emits "open" event', async () => {
const { fs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' });
const readStream = fs.createReadStream('/folder/file');
const fd = yield new Promise(resolve => readStream.once('open', resolve));
const fd = await new Promise(resolve => readStream.once('open', resolve));
expect(typeof fd).toBe('number');
}));
test('emits "ready" event', () => __awaiter(void 0, void 0, void 0, function* () {
});
test('emits "ready" event', async () => {
const { fs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' });
const readStream = fs.createReadStream('/folder/file');
yield new Promise(resolve => readStream.once('ready', resolve));
}));
test('emits "close" event', () => __awaiter(void 0, void 0, void 0, function* () {
await new Promise(resolve => readStream.once('ready', resolve));
});
test('emits "close" event', async () => {
const { fs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' });

@@ -897,12 +905,12 @@ const readStream = fs.createReadStream('/folder/file', { emitClose: true });

readStream.pipe(writeStream);
yield new Promise(resolve => readStream.once('close', resolve));
}));
test('can write to already open file', () => __awaiter(void 0, void 0, void 0, function* () {
const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' });
const handle = yield fs.promises.open('/folder/file');
await new Promise(resolve => readStream.once('close', resolve));
});
test('can write to already open file', async () => {
const { fs, vol } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' });
const handle = await fs.promises.open('/folder/file');
const readStream = fs.createReadStream('xyz', { fd: handle.fd });
const writeStream = fs.createWriteStream('/folder/file2');
readStream.pipe(writeStream);
yield new Promise(resolve => writeStream.once('close', resolve));
expect(mfs.__vol.toJSON()).toStrictEqual({
await new Promise(resolve => writeStream.once('close', resolve));
expect(vol.toJSON()).toStrictEqual({
'/mountpoint/folder/file': 'test',

@@ -913,10 +921,10 @@ '/mountpoint/folder/file2': 'test',

});
}));
test('can read a specified slice of a file', () => __awaiter(void 0, void 0, void 0, function* () {
const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' });
});
test('can read a specified slice of a file', async () => {
const { fs, vol } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' });
const readStream = fs.createReadStream('/folder/file', { start: 1, end: 2 });
const writeStream = fs.createWriteStream('/folder/file2');
readStream.pipe(writeStream);
yield new Promise(resolve => writeStream.once('close', resolve));
expect(mfs.__vol.toJSON()).toStrictEqual({
await new Promise(resolve => writeStream.once('close', resolve));
expect(vol.toJSON()).toStrictEqual({
'/mountpoint/folder/file': 'test',

@@ -927,4 +935,5 @@ '/mountpoint/folder/file2': 'es',

});
}));
});
});
});
//# sourceMappingURL=FsaNodeFs.test.js.map

@@ -14,2 +14,5 @@ "use strict";

});
test('strips trailing slash', () => {
expect((0, util_1.pathToLocation)('scary.exe/')).toStrictEqual([[], 'scary.exe']);
});
test('multiple steps in the path', () => {

@@ -30,1 +33,2 @@ expect((0, util_1.pathToLocation)('/gg/wp/hf/gl.txt')).toStrictEqual([['gg', 'wp', 'hf'], 'gl.txt']);

});
//# sourceMappingURL=util.test.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=constants.js.map

@@ -24,10 +24,11 @@ import { FsaNodeFsOpenFile } from './FsaNodeFsOpenFile';

protected getFile(path: string[], name: string, funcName?: string, create?: boolean): Promise<fsa.IFileSystemFileHandle>;
protected getFileOrDir(path: string[], name: string, funcName?: string, create?: boolean): Promise<fsa.IFileSystemFileHandle | fsa.IFileSystemDirectoryHandle>;
protected getFileOrDir(path: string[], name: string, funcName?: string): Promise<fsa.IFileSystemFileHandle | fsa.IFileSystemDirectoryHandle>;
protected getFileByFd(fd: number, funcName?: string): FsaNodeFsOpenFile;
protected getFileByFdAsync(fd: number, funcName?: string): Promise<FsaNodeFsOpenFile>;
__getFileById(id: misc.TFileId, funcName?: string, create?: boolean): Promise<fsa.IFileSystemFileHandle>;
__getFileById(id: misc.TFileId, funcName?: string): Promise<fsa.IFileSystemFileHandle>;
protected getFileByIdOrCreate(id: misc.TFileId, funcName?: string): Promise<fsa.IFileSystemFileHandle>;
protected __open(filename: string, flags: number, mode: number): Promise<FsaNodeFsOpenFile>;
protected __open2(fsaFile: fsa.IFileSystemFileHandle, filename: string, flags: number, mode: number): FsaNodeFsOpenFile;
protected __close(fd: number): Promise<void>;
protected getFileName(id: misc.TFileId): string;
}
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -17,2 +8,3 @@ exports.FsaNodeCore = void 0;

const FsaNodeFsOpenFile_1 = require("./FsaNodeFsOpenFile");
const util = require("../node/util");
class FsaNodeCore {

@@ -50,63 +42,59 @@ constructor(root, syncAdapter) {

*/
getDir(path, create, funcName) {
return __awaiter(this, void 0, void 0, function* () {
let curr = yield this.root;
const options = { create };
try {
for (const name of path) {
curr = yield curr.getDirectoryHandle(name, options);
}
async getDir(path, create, funcName) {
let curr = await this.root;
const options = { create };
try {
for (const name of path) {
curr = await curr.getDirectoryHandle(name, options);
}
catch (error) {
if (error && typeof error === 'object') {
switch (error.name) {
case 'TypeMismatchError':
throw (0, util_1.createError)('ENOTDIR', funcName, path.join("/" /* FsaToNodeConstants.Separator */));
case 'NotFoundError':
throw (0, util_1.createError)('ENOENT', funcName, path.join("/" /* FsaToNodeConstants.Separator */));
}
}
catch (error) {
if (error && typeof error === 'object') {
switch (error.name) {
case 'TypeMismatchError':
throw (0, util_1.createError)('ENOTDIR', funcName, path.join("/" /* FsaToNodeConstants.Separator */));
case 'NotFoundError':
throw (0, util_1.createError)('ENOENT', funcName, path.join("/" /* FsaToNodeConstants.Separator */));
}
throw error;
}
return curr;
});
throw error;
}
return curr;
}
getFile(path, name, funcName, create) {
return __awaiter(this, void 0, void 0, function* () {
const dir = yield this.getDir(path, false, funcName);
const file = yield dir.getFileHandle(name, { create });
async getFile(path, name, funcName, create) {
const dir = await this.getDir(path, false, funcName);
const file = await dir.getFileHandle(name, { create });
return file;
}
async getFileOrDir(path, name, funcName) {
const dir = await this.getDir(path, false, funcName);
if (!name)
return dir;
try {
const file = await dir.getFileHandle(name);
return file;
});
}
getFileOrDir(path, name, funcName, create) {
return __awaiter(this, void 0, void 0, function* () {
const dir = yield this.getDir(path, false, funcName);
try {
const file = yield dir.getFileHandle(name);
return file;
}
catch (error) {
if (error && typeof error === 'object') {
switch (error.name) {
case 'TypeMismatchError':
try {
return yield dir.getDirectoryHandle(name);
}
catch (error2) {
if (error2 && typeof error2 === 'object') {
switch (error2.name) {
case 'TypeMismatchError':
throw (0, util_1.createError)('ENOTDIR', funcName, path.join("/" /* FsaToNodeConstants.Separator */));
case 'NotFoundError':
throw (0, util_1.createError)('ENOENT', funcName, path.join("/" /* FsaToNodeConstants.Separator */));
}
}
catch (error) {
if (error && typeof error === 'object') {
switch (error.name) {
case 'TypeMismatchError':
try {
return await dir.getDirectoryHandle(name);
}
catch (error2) {
if (error2 && typeof error2 === 'object') {
switch (error2.name) {
case 'TypeMismatchError':
throw (0, util_1.createError)('ENOTDIR', funcName, path.join("/" /* FsaToNodeConstants.Separator */));
case 'NotFoundError':
throw (0, util_1.createError)('ENOENT', funcName, path.join("/" /* FsaToNodeConstants.Separator */));
}
}
case 'NotFoundError':
throw (0, util_1.createError)('ENOENT', funcName, path.join("/" /* FsaToNodeConstants.Separator */));
}
}
case 'NotFoundError':
throw (0, util_1.createError)('ENOENT', funcName, path.join("/" /* FsaToNodeConstants.Separator */));
}
throw error;
}
});
throw error;
}
}

@@ -121,33 +109,59 @@ getFileByFd(fd, funcName) {

}
getFileByFdAsync(fd, funcName) {
return __awaiter(this, void 0, void 0, function* () {
return this.getFileByFd(fd, funcName);
});
async getFileByFdAsync(fd, funcName) {
return this.getFileByFd(fd, funcName);
}
__getFileById(id, funcName, create) {
return __awaiter(this, void 0, void 0, function* () {
if (typeof id === 'number')
return (yield this.getFileByFd(id, funcName)).file;
const filename = (0, util_1.pathToFilename)(id);
const [folder, name] = (0, util_2.pathToLocation)(filename);
return yield this.getFile(folder, name, funcName, create);
});
async __getFileById(id, funcName) {
if (typeof id === 'number')
return (await this.getFileByFd(id, funcName)).file;
const filename = (0, util_1.pathToFilename)(id);
const [folder, name] = (0, util_2.pathToLocation)(filename);
return await this.getFile(folder, name, funcName);
}
getFileByIdOrCreate(id, funcName) {
return __awaiter(this, void 0, void 0, function* () {
if (typeof id === 'number')
return (yield this.getFileByFd(id, funcName)).file;
const filename = (0, util_1.pathToFilename)(id);
const [folder, name] = (0, util_2.pathToLocation)(filename);
const dir = yield this.getDir(folder, false, funcName);
return yield dir.getFileHandle(name, { create: true });
});
async getFileByIdOrCreate(id, funcName) {
if (typeof id === 'number')
return (await this.getFileByFd(id, funcName)).file;
const filename = (0, util_1.pathToFilename)(id);
const [folder, name] = (0, util_2.pathToLocation)(filename);
const dir = await this.getDir(folder, false, funcName);
return await dir.getFileHandle(name, { create: true });
}
__open(filename, flags, mode) {
return __awaiter(this, void 0, void 0, function* () {
const [folder, name] = (0, util_2.pathToLocation)(filename);
async __open(filename, flags, mode) {
const [folder, name] = (0, util_2.pathToLocation)(filename);
const throwIfExists = !!(flags & 128 /* FLAG.O_EXCL */);
if (throwIfExists) {
try {
await this.getFile(folder, name, 'open', false);
throw util.createError('EEXIST', 'writeFile');
}
catch (error) {
const file404 = error && typeof error === 'object' && (error.code === 'ENOENT' || error.name === 'NotFoundError');
if (!file404) {
if (error && typeof error === 'object') {
switch (error.name) {
case 'TypeMismatchError':
throw (0, util_1.createError)('ENOTDIR', 'open', filename);
case 'NotFoundError':
throw (0, util_1.createError)('ENOENT', 'open', filename);
}
}
throw error;
}
}
}
try {
const createIfMissing = !!(flags & 64 /* FLAG.O_CREAT */);
const fsaFile = yield this.getFile(folder, name, 'open', createIfMissing);
const fsaFile = await this.getFile(folder, name, 'open', createIfMissing);
return this.__open2(fsaFile, filename, flags, mode);
});
}
catch (error) {
if (error && typeof error === 'object') {
switch (error.name) {
case 'TypeMismatchError':
throw (0, util_1.createError)('ENOTDIR', 'open', filename);
case 'NotFoundError':
throw (0, util_1.createError)('ENOENT', 'open', filename);
}
}
throw error;
}
}

@@ -160,2 +174,9 @@ __open2(fsaFile, filename, flags, mode) {

}
async __close(fd) {
const openFile = await this.getFileByFdAsync(fd, 'close');
await openFile.close();
const deleted = this.fds.delete(fd);
if (deleted)
this.releasedFds.push(fd);
}
getFileName(id) {

@@ -173,1 +194,2 @@ if (typeof id === 'number') {

FsaNodeCore.fd = 0x7fffffff;
//# sourceMappingURL=FsaNodeCore.js.map

@@ -32,1 +32,2 @@ "use strict";

exports.FsaNodeDirent = FsaNodeDirent;
//# sourceMappingURL=FsaNodeDirent.js.map

@@ -63,4 +63,8 @@ import { FsaNodeDirent } from './FsaNodeDirent';

readonly createReadStream: FsCallbackApi['createReadStream'];
readonly symlink: FsCallbackApi['symlink'];
readonly link: FsCallbackApi['link'];
readonly cp: FsCallbackApi['cp'];
readonly lutimes: FsCallbackApi['lutimes'];
readonly openAsBlob: FsCallbackApi['openAsBlob'];
readonly opendir: FsCallbackApi['opendir'];
readonly readv: FsCallbackApi['readv'];
readonly statfs: FsCallbackApi['statfs'];
/**

@@ -74,2 +78,4 @@ * @todo Watchers could be implemented in the future on top of `FileSystemObserver`,

readonly watch: FsCallbackApi['watch'];
readonly symlink: FsCallbackApi['symlink'];
readonly link: FsCallbackApi['link'];
readonly statSync: FsSynchronousApi['statSync'];

@@ -99,2 +105,3 @@ readonly lstatSync: FsSynchronousApi['lstatSync'];

readonly openSync: FsSynchronousApi['openSync'];
readonly writevSync: FsSynchronousApi['writevSync'];
readonly fdatasyncSync: FsSynchronousApi['fdatasyncSync'];

@@ -110,2 +117,7 @@ readonly fsyncSync: FsSynchronousApi['fsyncSync'];

readonly utimesSync: FsSynchronousApi['utimesSync'];
readonly lutimesSync: FsSynchronousApi['lutimesSync'];
readonly cpSync: FsSynchronousApi['cpSync'];
readonly opendirSync: FsSynchronousApi['opendirSync'];
readonly statfsSync: FsSynchronousApi['statfsSync'];
readonly readvSync: FsSynchronousApi['readvSync'];
readonly symlinkSync: FsSynchronousApi['symlinkSync'];

@@ -112,0 +124,0 @@ readonly linkSync: FsSynchronousApi['linkSync'];

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __asyncValues = (this && this.__asyncValues) || function (o) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var m = o[Symbol.asyncIterator], i;
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.FsaNodeFs = void 0;
const tslib_1 = require("tslib");
const optHelpers = require("../node/options");
const util = require("../node/util");
const promises_1 = require("../node/promises");
const FsPromises_1 = require("../node/FsPromises");
const util_1 = require("./util");

@@ -33,5 +18,9 @@ const constants_1 = require("../node/constants");

const FsaNodeCore_1 = require("./FsaNodeCore");
const FileHandle_1 = require("../node/FileHandle");
const notSupported = () => {
throw new Error('Method not supported by the File System Access API.');
};
const notImplemented = () => {
throw new Error('Not implemented');
};
const noop = () => { };

@@ -46,3 +35,3 @@ /**

super(...arguments);
this.promises = (0, promises_1.createPromisesApi)(this);
this.promises = new FsPromises_1.FsPromises(this, FileHandle_1.FileHandle);
// ------------------------------------------------------------ FsCallbackApi

@@ -64,11 +53,3 @@ this.open = (path, flags, a, b) => {

util.validateFd(fd);
this.getFileByFdAsync(fd, 'close')
.then(file => file.close())
.then(() => {
this.fds.delete(fd);
this.releasedFds.push(fd);
callback(null);
}, error => {
callback(error);
});
this.__close(fd).then(() => callback(null), error => callback(error));
};

@@ -84,6 +65,6 @@ this.read = (fd, buffer, offset, length, position, callback) => {

}
(() => __awaiter(this, void 0, void 0, function* () {
const openFile = yield this.getFileByFd(fd, 'read');
const file = yield openFile.file.getFile();
const src = yield file.arrayBuffer();
(async () => {
const openFile = await this.getFileByFd(fd, 'read');
const file = await openFile.file.getFile();
const src = await file.arrayBuffer();
const slice = new Uint8Array(src, Number(position), Number(length));

@@ -93,3 +74,3 @@ const dest = new Uint8Array(buffer.buffer, buffer.byteOffset + offset, slice.length);

return slice.length;
}))().then(bytesWritten => callback(null, bytesWritten, buffer), error => callback(error));
})().then(bytesWritten => callback(null, bytesWritten, buffer), error => callback(error));
};

@@ -99,21 +80,35 @@ this.readFile = (id, a, b) => {

const flagsNum = util.flagsToNumber(opts.flag);
return this.__getFileById(id, 'readFile')
.then(file => file.getFile())
.then(file => file.arrayBuffer())
.then(data => {
const buffer = Buffer.from(data);
callback(null, util.bufferToEncoding(buffer, opts.encoding));
})
.catch(error => {
callback(error);
});
(async () => {
let fd = typeof id === 'number' ? id : -1;
const originalFd = fd;
try {
if (fd === -1) {
const filename = util.pathToFilename(id);
fd = (await this.__open(filename, flagsNum, 0)).fd;
}
const handle = await this.__getFileById(fd, 'readFile');
const file = await handle.getFile();
const buffer = Buffer.from(await file.arrayBuffer());
return util.bufferToEncoding(buffer, opts.encoding);
}
finally {
try {
const idWasFd = typeof originalFd === 'number' && originalFd >= 0;
if (idWasFd)
await this.__close(originalFd);
}
catch (_a) { }
}
})()
.then(data => callback(null, data))
.catch(error => callback(error));
};
this.write = (fd, a, b, c, d, e) => {
const [, asStr, buf, offset, length, position, cb] = util.getWriteArgs(fd, a, b, c, d, e);
(() => __awaiter(this, void 0, void 0, function* () {
const openFile = yield this.getFileByFd(fd, 'write');
(async () => {
const openFile = await this.getFileByFd(fd, 'write');
const data = buf.subarray(offset, offset + length);
yield openFile.write(data, position);
await openFile.write(data, position);
return length;
}))().then(bytesWritten => cb(null, bytesWritten, asStr ? a : buf), error => cb(error));
})().then(bytesWritten => cb(null, bytesWritten, asStr ? a : buf), error => cb(error));
};

@@ -132,4 +127,4 @@ this.writev = (fd, buffers, a, b) => {

util.validateCallback(callback);
(() => __awaiter(this, void 0, void 0, function* () {
const openFile = yield this.getFileByFd(fd, 'writev');
(async () => {
const openFile = await this.getFileByFd(fd, 'writev');
const length = buffers.length;

@@ -139,3 +134,3 @@ let bytesWritten = 0;

const data = buffers[i];
yield openFile.write(data, position);
await openFile.write(data, position);
bytesWritten += data.byteLength;

@@ -145,3 +140,3 @@ position = null;

return bytesWritten;
}))().then(bytesWritten => callback(null, bytesWritten, buffers), error => callback(error));
})().then(bytesWritten => callback(null, bytesWritten, buffers), error => callback(error));
};

@@ -160,9 +155,24 @@ this.writeFile = (id, data, a, b) => {

const buf = util.dataToBuffer(data, opts.encoding);
(() => __awaiter(this, void 0, void 0, function* () {
const createIfMissing = !!(flagsNum & 64 /* FLAG.O_CREAT */);
const file = yield this.__getFileById(id, 'writeFile', createIfMissing);
const writable = yield file.createWritable({ keepExistingData: false });
yield writable.write(buf);
yield writable.close();
}))().then(() => cb(null), error => cb(error));
(async () => {
let fd = typeof id === 'number' ? id : -1;
const originalFd = fd;
try {
if (fd === -1) {
const filename = util.pathToFilename(id);
fd = (await this.__open(filename, flagsNum, modeNum)).fd;
}
const file = await this.__getFileById(fd, 'writeFile');
const writable = await file.createWritable({ keepExistingData: false });
await writable.write(buf);
await writable.close();
}
finally {
try {
const idWasFd = typeof originalFd === 'number' && originalFd >= 0;
if (idWasFd)
await this.__close(originalFd);
}
catch (_a) { }
}
})().then(() => cb(null), error => cb(error));
};

@@ -185,11 +195,11 @@ this.copyFile = (src, dest, a, b) => {

const [newFolder, newName] = (0, util_1.pathToLocation)(destFilename);
(() => __awaiter(this, void 0, void 0, function* () {
const oldFile = yield this.getFile(oldFolder, oldName, 'copyFile');
const newDir = yield this.getDir(newFolder, false, 'copyFile');
const newFile = yield newDir.getFileHandle(newName, { create: true });
const writable = yield newFile.createWritable({ keepExistingData: false });
const oldData = yield oldFile.getFile();
yield writable.write(yield oldData.arrayBuffer());
yield writable.close();
}))().then(() => callback(null), error => callback(error));
(async () => {
const oldFile = await this.getFile(oldFolder, oldName, 'copyFile');
const newDir = await this.getDir(newFolder, false, 'copyFile');
const newFile = await newDir.getFileHandle(newName, { create: true });
const writable = await newFile.createWritable({ keepExistingData: false });
const oldData = await oldFile.getFile();
await writable.write(await oldData.arrayBuffer());
await writable.close();
})().then(() => callback(null), error => callback(error));
};

@@ -232,6 +242,6 @@ /**

const [folder, name] = (0, util_1.pathToLocation)(filename);
(() => __awaiter(this, void 0, void 0, function* () {
const handle = yield this.getFileOrDir(folder, name, 'stat');
return yield this.getHandleStats(bigint, handle);
}))().then(stats => callback(null, stats), error => callback(error));
(async () => {
const handle = await this.getFileOrDir(folder, name, 'stat');
return await this.getHandleStats(bigint, handle);
})().then(stats => callback(null, stats), error => callback(error));
};

@@ -241,6 +251,6 @@ this.lstat = this.stat;

const [{ bigint = false, throwIfNoEntry = true }, callback] = optHelpers.getStatOptsAndCb(a, b);
(() => __awaiter(this, void 0, void 0, function* () {
const openFile = yield this.getFileByFd(fd, 'fstat');
return yield this.getHandleStats(bigint, openFile.file);
}))().then(stats => callback(null, stats), error => callback(error));
(async () => {
const openFile = await this.getFileByFd(fd, 'fstat');
return await this.getHandleStats(bigint, openFile.file);
})().then(stats => callback(null, stats), error => callback(error));
};

@@ -256,13 +266,13 @@ /**

const [newFolder, newName] = (0, util_1.pathToLocation)(newPathFilename);
(() => __awaiter(this, void 0, void 0, function* () {
const oldFile = yield this.getFile(oldFolder, oldName, 'rename');
const newDir = yield this.getDir(newFolder, false, 'rename');
const newFile = yield newDir.getFileHandle(newName, { create: true });
const writable = yield newFile.createWritable({ keepExistingData: false });
const oldData = yield oldFile.getFile();
yield writable.write(yield oldData.arrayBuffer());
yield writable.close();
const oldDir = yield this.getDir(oldFolder, false, 'rename');
yield oldDir.removeEntry(oldName);
}))().then(() => callback(null), error => callback(error));
(async () => {
const oldFile = await this.getFile(oldFolder, oldName, 'rename');
const newDir = await this.getDir(newFolder, false, 'rename');
const newFile = await newDir.getFileHandle(newName, { create: true });
const writable = await newFile.createWritable({ keepExistingData: false });
const oldData = await oldFile.getFile();
await writable.write(await oldData.arrayBuffer());
await writable.close();
const oldDir = await this.getDir(oldFolder, false, 'rename');
await oldDir.removeEntry(oldName);
})().then(() => callback(null), error => callback(error));
};

@@ -287,4 +297,4 @@ this.exists = (path, callback) => {

const [folder, name] = (0, util_1.pathToLocation)(filename);
(() => __awaiter(this, void 0, void 0, function* () {
const node = folder.length || name ? yield this.getFileOrDir(folder, name, 'access') : yield this.root;
(async () => {
const node = folder.length || name ? await this.getFileOrDir(folder, name, 'access') : await this.root;
const checkIfCanExecute = mode & 1 /* AMODE.X_OK */;

@@ -299,4 +309,4 @@ if (checkIfCanExecute)

const file = node;
const writable = yield file.createWritable();
yield writable.close();
const writable = await file.createWritable();
await writable.close();
}

@@ -312,3 +322,3 @@ catch (_a) {

const dir = node;
const canWrite = yield (0, util_1.testDirectoryIsWritable)(dir);
const canWrite = await (0, util_1.testDirectoryIsWritable)(dir);
if (!canWrite)

@@ -323,3 +333,3 @@ throw util.createError('EACCESS', 'access', filename);

}
}))().then(() => callback(null), error => callback(error));
})().then(() => callback(null), error => callback(error));
};

@@ -330,6 +340,6 @@ this.appendFile = (id, data, a, b) => {

this.getFileByIdOrCreate(id, 'appendFile')
.then(file => (() => __awaiter(this, void 0, void 0, function* () {
const blob = yield file.getFile();
const writable = yield file.createWritable({ keepExistingData: true });
yield writable.write({
.then(file => (async () => {
const blob = await file.getFile();
const writable = await file.createWritable({ keepExistingData: true });
await writable.write({
type: 'write',

@@ -339,4 +349,4 @@ data: buffer,

});
yield writable.close();
}))())
await writable.close();
})())
.then(() => callback(null), error => callback(error));

@@ -351,3 +361,3 @@ };

this.getDir(folder, false, 'readdir')
.then(dir => (() => __awaiter(this, void 0, void 0, function* () {
.then(dir => (async () => {
var _a, e_1, _b, _c, _d, e_2, _e, _f;

@@ -357,13 +367,8 @@ if (options.withFileTypes) {

try {
for (var _g = true, _h = __asyncValues(dir.entries()), _j; _j = yield _h.next(), _a = _j.done, !_a;) {
for (var _g = true, _h = tslib_1.__asyncValues(dir.entries()), _j; _j = await _h.next(), _a = _j.done, !_a; _g = true) {
_c = _j.value;
_g = false;
try {
const [name, handle] = _c;
const dirent = new FsaNodeDirent_1.FsaNodeDirent(name, handle.kind);
list.push(dirent);
}
finally {
_g = true;
}
const [name, handle] = _c;
const dirent = new FsaNodeDirent_1.FsaNodeDirent(name, handle.kind);
list.push(dirent);
}

@@ -374,3 +379,3 @@ }

try {
if (!_g && !_a && (_b = _h.return)) yield _b.call(_h);
if (!_g && !_a && (_b = _h.return)) await _b.call(_h);
}

@@ -392,12 +397,7 @@ finally { if (e_1) throw e_1.error; }

try {
for (var _k = true, _l = __asyncValues(dir.keys()), _m; _m = yield _l.next(), _d = _m.done, !_d;) {
for (var _k = true, _l = tslib_1.__asyncValues(dir.keys()), _m; _m = await _l.next(), _d = _m.done, !_d; _k = true) {
_f = _m.value;
_k = false;
try {
const key = _f;
list.push(key);
}
finally {
_k = true;
}
const key = _f;
list.push(key);
}

@@ -408,3 +408,3 @@ }

try {
if (!_k && !_d && (_e = _l.return)) yield _e.call(_l);
if (!_k && !_d && (_e = _l.return)) await _e.call(_l);
}

@@ -417,3 +417,3 @@ finally { if (e_2) throw e_2.error; }

}
}))())
})())
.then(res => callback(null, res), err => callback(err));

@@ -620,4 +620,8 @@ };

};
this.symlink = notSupported;
this.link = notSupported;
this.cp = notImplemented;
this.lutimes = notImplemented;
this.openAsBlob = notImplemented;
this.opendir = notImplemented;
this.readv = notImplemented;
this.statfs = notImplemented;
/**

@@ -631,2 +635,4 @@ * @todo Watchers could be implemented in the future on top of `FileSystemObserver`,

this.watch = notSupported;
this.symlink = notSupported;
this.link = notSupported;
// --------------------------------------------------------- FsSynchronousApi

@@ -804,2 +810,10 @@ this.statSync = (path, options) => {

};
this.writevSync = (fd, buffers, position) => {
if (buffers.length === 0)
return;
this.writeSync(fd, buffers[0], 0, buffers[0].byteLength, position);
for (let i = 1; i < buffers.length; i++) {
this.writeSync(fd, buffers[i], 0, buffers[i].byteLength, null);
}
};
this.fdatasyncSync = noop;

@@ -815,2 +829,7 @@ this.fsyncSync = noop;

this.utimesSync = noop;
this.lutimesSync = noop;
this.cpSync = notImplemented;
this.opendirSync = notImplemented;
this.statfsSync = notImplemented;
this.readvSync = notImplemented;
this.symlinkSync = notSupported;

@@ -833,29 +852,22 @@ this.linkSync = notSupported;

}
getHandleStats(bigint, handle) {
return __awaiter(this, void 0, void 0, function* () {
let size = 0;
if (handle.kind === 'file') {
const file = handle;
const fileData = yield file.getFile();
size = fileData.size;
}
const stats = new FsaNodeStats_1.FsaNodeStats(bigint, bigint ? BigInt(size) : size, handle.kind);
return stats;
});
async getHandleStats(bigint, handle) {
let size = 0;
if (handle.kind === 'file') {
const file = handle;
const fileData = await file.getFile();
size = fileData.size;
}
const stats = new FsaNodeStats_1.FsaNodeStats(bigint, bigint ? BigInt(size) : size, handle.kind);
return stats;
}
rmAll(callback) {
(() => __awaiter(this, void 0, void 0, function* () {
(async () => {
var _a, e_3, _b, _c;
const root = yield this.root;
const root = await this.root;
try {
for (var _d = true, _e = __asyncValues(root.keys()), _f; _f = yield _e.next(), _a = _f.done, !_a;) {
for (var _d = true, _e = tslib_1.__asyncValues(root.keys()), _f; _f = await _e.next(), _a = _f.done, !_a; _d = true) {
_c = _f.value;
_d = false;
try {
const name = _c;
yield root.removeEntry(name, { recursive: true });
}
finally {
_d = true;
}
const name = _c;
await root.removeEntry(name, { recursive: true });
}

@@ -866,9 +878,10 @@ }

try {
if (!_d && !_a && (_b = _e.return)) yield _b.call(_e);
if (!_d && !_a && (_b = _e.return)) await _b.call(_e);
}
finally { if (e_3) throw e_3.error; }
}
}))().then(() => callback(null), error => callback(error));
})().then(() => callback(null), error => callback(error));
}
}
exports.FsaNodeFs = FsaNodeFs;
//# sourceMappingURL=FsaNodeFs.js.map
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -27,21 +18,18 @@ exports.FsaNodeFsOpenFile = void 0;

}
close() {
return __awaiter(this, void 0, void 0, function* () { });
}
write(data, seek) {
return __awaiter(this, void 0, void 0, function* () {
if (typeof seek !== 'number')
seek = this.seek;
const writer = yield this.file.createWritable({ keepExistingData: this.keepExistingData });
yield writer.write({
type: 'write',
data,
position: seek,
});
yield writer.close();
this.keepExistingData = true;
this.seek += data.byteLength;
async close() { }
async write(data, seek) {
if (typeof seek !== 'number')
seek = this.seek;
const writer = await this.file.createWritable({ keepExistingData: this.keepExistingData });
await writer.write({
type: 'write',
data,
position: seek,
});
await writer.close();
this.keepExistingData = true;
this.seek += data.byteLength;
}
}
exports.FsaNodeFsOpenFile = FsaNodeFsOpenFile;
//# sourceMappingURL=FsaNodeFsOpenFile.js.map
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -44,17 +35,15 @@ exports.FsaNodeReadStream = void 0;

}
__read__() {
return __awaiter(this, void 0, void 0, function* () {
return yield this.__mutex__(() => __awaiter(this, void 0, void 0, function* () {
if (this.__closed__)
return;
const { file } = yield this.__file__.promise;
const blob = yield file.getFile();
const buffer = yield blob.arrayBuffer();
const start = this.options.start || 0;
let end = typeof this.options.end === 'number' ? this.options.end + 1 : buffer.byteLength;
if (end > buffer.byteLength)
end = buffer.byteLength;
const uint8 = new Uint8Array(buffer, start, end - start);
return uint8;
}));
async __read__() {
return await this.__mutex__(async () => {
if (this.__closed__)
return;
const { file } = await this.__file__.promise;
const blob = await file.getFile();
const buffer = await blob.arrayBuffer();
const start = this.options.start || 0;
let end = typeof this.options.end === 'number' ? this.options.end + 1 : buffer.byteLength;
if (end > buffer.byteLength)
end = buffer.byteLength;
const uint8 = new Uint8Array(buffer, start, end - start);
return uint8;
});

@@ -102,1 +91,2 @@ }

exports.FsaNodeReadStream = FsaNodeReadStream;
//# sourceMappingURL=FsaNodeReadStream.js.map

@@ -53,1 +53,2 @@ "use strict";

exports.FsaNodeStats = FsaNodeStats;
//# sourceMappingURL=FsaNodeStats.js.map
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -57,5 +48,5 @@ exports.FsaNodeWriteStream = void 0;

this.__stream__ = stream.promise;
(() => __awaiter(this, void 0, void 0, function* () {
(async () => {
var _a, _b;
const fsaHandle = yield handle;
const fsaHandle = await handle;
const fileWasOpened = !options.fd;

@@ -66,49 +57,45 @@ if (fileWasOpened)

const keepExistingData = flags & 1024 /* FLAG.O_APPEND */ ? true : false;
const writable = yield fsaHandle.file.createWritable({ keepExistingData });
const writable = await fsaHandle.file.createWritable({ keepExistingData });
if (keepExistingData) {
const start = Number((_b = options.start) !== null && _b !== void 0 ? _b : 0);
if (start)
yield writable.seek(start);
await writable.seek(start);
}
this.__pending__ = false;
stream.resolve(writable);
}))().catch(error => {
})().catch(error => {
stream.reject(error);
});
}
___write___(buffers) {
return __awaiter(this, void 0, void 0, function* () {
yield this.__mutex__(() => __awaiter(this, void 0, void 0, function* () {
if (this.__closed__)
return;
// if (this.__closed__) throw new Error('WriteStream is closed');
const writable = yield this.__stream__;
for (const buffer of buffers) {
yield writable.write(buffer);
this.__bytes__ += buffer.byteLength;
}
}));
async ___write___(buffers) {
await this.__mutex__(async () => {
if (this.__closed__)
return;
// if (this.__closed__) throw new Error('WriteStream is closed');
const writable = await this.__stream__;
for (const buffer of buffers) {
await writable.write(buffer);
this.__bytes__ += buffer.byteLength;
}
});
}
__close__() {
return __awaiter(this, void 0, void 0, function* () {
const emitClose = this.options.emitClose;
yield this.__mutex__(() => __awaiter(this, void 0, void 0, function* () {
if (this.__closed__ && emitClose) {
process.nextTick(() => this.emit('close'));
return;
}
try {
const writable = yield this.__stream__;
this.__closed__ = true;
yield writable.close();
if (emitClose)
this.emit('close');
}
catch (error) {
this.emit('error', error);
if (emitClose)
this.emit('close', error);
}
}));
async __close__() {
const emitClose = this.options.emitClose;
await this.__mutex__(async () => {
if (this.__closed__ && emitClose) {
process.nextTick(() => this.emit('close'));
return;
}
try {
const writable = await this.__stream__;
this.__closed__ = true;
await writable.close();
if (emitClose)
this.emit('close');
}
catch (error) {
this.emit('error', error);
if (emitClose)
this.emit('close', error);
}
});

@@ -165,1 +152,2 @@ }

exports.FsaNodeWriteStream = FsaNodeWriteStream;
//# sourceMappingURL=FsaNodeWriteStream.js.map

@@ -8,1 +8,2 @@ "use strict";

Object.defineProperty(exports, "FsaNodeSyncAdapterWorker", { enumerable: true, get: function () { return FsaNodeSyncAdapterWorker_1.FsaNodeSyncAdapterWorker; } });
//# sourceMappingURL=index.js.map

@@ -8,1 +8,2 @@ "use strict";

exports.decoder = new CborDecoder_1.CborDecoder();
//# sourceMappingURL=json.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=types.js.map
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -16,2 +7,4 @@ exports.testDirectoryIsWritable = exports.pathToLocation = void 0;

path = path.slice(1);
if (path[path.length - 1] === "/" /* FsaToNodeConstants.Separator */)
path = path.slice(0, -1);
const lastSlashIndex = path.lastIndexOf("/" /* FsaToNodeConstants.Separator */);

@@ -25,6 +18,6 @@ if (lastSlashIndex === -1)

exports.pathToLocation = pathToLocation;
const testDirectoryIsWritable = (dir) => __awaiter(void 0, void 0, void 0, function* () {
const testDirectoryIsWritable = async (dir) => {
const testFileName = '__memfs_writable_test_file_' + Math.random().toString(36).slice(2) + Date.now();
try {
yield dir.getFileHandle(testFileName, { create: true });
await dir.getFileHandle(testFileName, { create: true });
return true;

@@ -37,7 +30,8 @@ }

try {
yield dir.removeEntry(testFileName);
await dir.removeEntry(testFileName);
}
catch (e) { }
}
});
};
exports.testDirectoryIsWritable = testDirectoryIsWritable;
//# sourceMappingURL=util.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=constants.js.map
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -18,35 +9,33 @@ exports.FsaNodeSyncAdapterWorker = void 0;

class FsaNodeSyncAdapterWorker {
static start(url, dir) {
return __awaiter(this, void 0, void 0, function* () {
const worker = new Worker(url);
const future = new Defer_1.Defer();
let id = rootId++;
let messenger = undefined;
const _dir = yield dir;
worker.onmessage = e => {
const data = e.data;
if (!Array.isArray(data))
return;
const msg = data;
const code = msg[0];
switch (code) {
case 0 /* FsaNodeWorkerMessageCode.Init */: {
const [, sab] = msg;
messenger = new SyncMessenger_1.SyncMessenger(sab);
const setRootMessage = [1 /* FsaNodeWorkerMessageCode.SetRoot */, id, _dir];
worker.postMessage(setRootMessage);
break;
}
case 2 /* FsaNodeWorkerMessageCode.RootSet */: {
const [, rootId] = msg;
if (id !== rootId)
return;
const adapter = new FsaNodeSyncAdapterWorker(messenger, _dir);
future.resolve(adapter);
break;
}
static async start(url, dir) {
const worker = new Worker(url);
const future = new Defer_1.Defer();
let id = rootId++;
let messenger = undefined;
const _dir = await dir;
worker.onmessage = e => {
const data = e.data;
if (!Array.isArray(data))
return;
const msg = data;
const code = msg[0];
switch (code) {
case 0 /* FsaNodeWorkerMessageCode.Init */: {
const [, sab] = msg;
messenger = new SyncMessenger_1.SyncMessenger(sab);
const setRootMessage = [1 /* FsaNodeWorkerMessageCode.SetRoot */, id, _dir];
worker.postMessage(setRootMessage);
break;
}
};
return yield future.promise;
});
case 2 /* FsaNodeWorkerMessageCode.RootSet */: {
const [, rootId] = msg;
if (id !== rootId)
return;
const adapter = new FsaNodeSyncAdapterWorker(messenger, _dir);
future.resolve(adapter);
break;
}
}
};
return await future.promise;
}

@@ -74,1 +63,2 @@ constructor(messenger, root) {

exports.FsaNodeSyncAdapterWorker = FsaNodeSyncAdapterWorker;
//# sourceMappingURL=FsaNodeSyncAdapterWorker.js.map
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -33,3 +24,3 @@ exports.FsaNodeSyncWorker = void 0;

};
this.onRequest = (request) => __awaiter(this, void 0, void 0, function* () {
this.onRequest = async (request) => {
try {

@@ -46,3 +37,3 @@ const message = json_1.decoder.decode(request);

throw new Error(`Unknown method ${method}`);
const response = yield handler(payload);
const response = await handler(payload);
return json_1.encoder.encode([4 /* FsaNodeWorkerMessageCode.Response */, response]);

@@ -57,50 +48,50 @@ }

}
});
};
this.handlers = {
stat: (location) => __awaiter(this, void 0, void 0, function* () {
const handle = yield this.getFileOrDir(location[0], location[1], 'statSync');
stat: async (location) => {
const handle = await this.getFileOrDir(location[0], location[1], 'statSync');
return {
kind: handle.kind,
};
}),
access: ([filename, mode]) => __awaiter(this, void 0, void 0, function* () {
yield this.fs.promises.access(filename, mode);
}),
readFile: ([filename, opts]) => __awaiter(this, void 0, void 0, function* () {
const buf = (yield this.fs.promises.readFile(filename, Object.assign(Object.assign({}, opts), { encoding: 'buffer' })));
},
access: async ([filename, mode]) => {
await this.fs.promises.access(filename, mode);
},
readFile: async ([filename, opts]) => {
const buf = (await this.fs.promises.readFile(filename, Object.assign(Object.assign({}, opts), { encoding: 'buffer' })));
const uint8 = new Uint8Array(buf, buf.byteOffset, buf.byteLength);
return uint8;
}),
writeFile: ([filename, data, opts]) => __awaiter(this, void 0, void 0, function* () {
yield this.fs.promises.writeFile(filename, data, Object.assign(Object.assign({}, opts), { encoding: 'buffer' }));
}),
appendFile: ([filename, data, opts]) => __awaiter(this, void 0, void 0, function* () {
yield this.fs.promises.appendFile(filename, data, Object.assign(Object.assign({}, opts), { encoding: 'buffer' }));
}),
copy: ([src, dst, flags]) => __awaiter(this, void 0, void 0, function* () {
yield this.fs.promises.copyFile(src, dst, flags);
}),
move: ([src, dst]) => __awaiter(this, void 0, void 0, function* () {
yield this.fs.promises.rename(src, dst);
}),
rmdir: ([filename, options]) => __awaiter(this, void 0, void 0, function* () {
yield this.fs.promises.rmdir(filename, options);
}),
rm: ([filename, options]) => __awaiter(this, void 0, void 0, function* () {
yield this.fs.promises.rm(filename, options);
}),
mkdir: ([filename, options]) => __awaiter(this, void 0, void 0, function* () {
return yield this.fs.promises.mkdir(filename, options);
}),
mkdtemp: ([filename]) => __awaiter(this, void 0, void 0, function* () {
return (yield this.fs.promises.mkdtemp(filename, { encoding: 'utf8' }));
}),
trunc: ([filename, len]) => __awaiter(this, void 0, void 0, function* () {
yield this.fs.promises.truncate(filename, len);
}),
unlink: ([filename]) => __awaiter(this, void 0, void 0, function* () {
yield this.fs.promises.unlink(filename);
}),
readdir: ([filename]) => __awaiter(this, void 0, void 0, function* () {
const list = (yield this.fs.promises.readdir(filename, { withFileTypes: true, encoding: 'utf8' }));
},
writeFile: async ([filename, data, opts]) => {
await this.fs.promises.writeFile(filename, data, Object.assign(Object.assign({}, opts), { encoding: 'buffer' }));
},
appendFile: async ([filename, data, opts]) => {
await this.fs.promises.appendFile(filename, data, Object.assign(Object.assign({}, opts), { encoding: 'buffer' }));
},
copy: async ([src, dst, flags]) => {
await this.fs.promises.copyFile(src, dst, flags);
},
move: async ([src, dst]) => {
await this.fs.promises.rename(src, dst);
},
rmdir: async ([filename, options]) => {
await this.fs.promises.rmdir(filename, options);
},
rm: async ([filename, options]) => {
await this.fs.promises.rm(filename, options);
},
mkdir: async ([filename, options]) => {
return await this.fs.promises.mkdir(filename, options);
},
mkdtemp: async ([filename]) => {
return (await this.fs.promises.mkdtemp(filename, { encoding: 'utf8' }));
},
trunc: async ([filename, len]) => {
await this.fs.promises.truncate(filename, len);
},
unlink: async ([filename]) => {
await this.fs.promises.unlink(filename);
},
readdir: async ([filename]) => {
const list = (await this.fs.promises.readdir(filename, { withFileTypes: true, encoding: 'utf8' }));
const res = list.map(entry => ({

@@ -111,7 +102,7 @@ kind: entry.isDirectory() ? 'directory' : 'file',

return res;
}),
read: ([filename, position, length]) => __awaiter(this, void 0, void 0, function* () {
},
read: async ([filename, position, length]) => {
let uint8 = new Uint8Array(length);
const handle = yield this.fs.promises.open(filename, 'r');
const bytesRead = yield new Promise((resolve, reject) => {
const handle = await this.fs.promises.open(filename, 'r');
const bytesRead = await new Promise((resolve, reject) => {
this.fs.read(handle.fd, uint8, 0, length, position, (err, bytesRead) => {

@@ -126,14 +117,14 @@ if (err)

return uint8;
}),
write: ([filename, data, position]) => __awaiter(this, void 0, void 0, function* () {
const handle = yield this.fs.promises.open(filename, 'a');
const { bytesWritten } = yield handle.write(data, 0, data.length, position || undefined);
},
write: async ([filename, data, position]) => {
const handle = await this.fs.promises.open(filename, 'a');
const { bytesWritten } = await handle.write(data, 0, data.length, position || undefined);
return bytesWritten;
}),
open: ([filename, flags, mode]) => __awaiter(this, void 0, void 0, function* () {
const handle = yield this.fs.promises.open(filename, flags, mode);
const file = yield this.fs.__getFileById(handle.fd);
yield handle.close();
},
open: async ([filename, flags, mode]) => {
const handle = await this.fs.promises.open(filename, flags, mode);
const file = await this.fs.__getFileById(handle.fd);
await handle.close();
return file;
}),
},
};

@@ -150,47 +141,42 @@ }

}
getDir(path, create, funcName) {
return __awaiter(this, void 0, void 0, function* () {
let curr = this.root;
const options = { create };
try {
for (const name of path) {
curr = yield curr.getDirectoryHandle(name, options);
}
async getDir(path, create, funcName) {
let curr = this.root;
const options = { create };
try {
for (const name of path) {
curr = await curr.getDirectoryHandle(name, options);
}
catch (error) {
// if (error && typeof error === 'object' && error.name === 'TypeMismatchError')
// throw createError('ENOTDIR', funcName, path.join(FsaToNodeConstants.Separator));
throw error;
}
return curr;
});
}
catch (error) {
// if (error && typeof error === 'object' && error.name === 'TypeMismatchError')
// throw createError('ENOTDIR', funcName, path.join(FsaToNodeConstants.Separator));
throw error;
}
return curr;
}
getFile(path, name, funcName, create) {
return __awaiter(this, void 0, void 0, function* () {
const dir = yield this.getDir(path, false, funcName);
const file = yield dir.getFileHandle(name, { create });
async getFile(path, name, funcName, create) {
const dir = await this.getDir(path, false, funcName);
const file = await dir.getFileHandle(name, { create });
return file;
}
async getFileOrDir(path, name, funcName, create) {
const dir = await this.getDir(path, false, funcName);
try {
const file = await dir.getFileHandle(name);
return file;
});
}
getFileOrDir(path, name, funcName, create) {
return __awaiter(this, void 0, void 0, function* () {
const dir = yield this.getDir(path, false, funcName);
try {
const file = yield dir.getFileHandle(name);
return file;
}
catch (error) {
if (error && typeof error === 'object') {
switch (error.name) {
case 'TypeMismatchError':
return yield dir.getDirectoryHandle(name);
// case 'NotFoundError':
// throw createError('ENOENT', funcName, path.join(FsaToNodeConstants.Separator));
}
}
catch (error) {
if (error && typeof error === 'object') {
switch (error.name) {
case 'TypeMismatchError':
return await dir.getDirectoryHandle(name);
// case 'NotFoundError':
// throw createError('ENOENT', funcName, path.join(FsaToNodeConstants.Separator));
}
throw error;
}
});
throw error;
}
}
}
exports.FsaNodeSyncWorker = FsaNodeSyncWorker;
//# sourceMappingURL=FsaNodeSyncWorker.js.map
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -61,3 +52,3 @@ exports.SyncMessenger = void 0;

const headerSize = this.headerSize;
(() => __awaiter(this, void 0, void 0, function* () {
(async () => {
try {

@@ -70,3 +61,3 @@ const int32 = this.int32;

const request = this.uint8.slice(headerSize, headerSize + requestLength);
const response = yield callback(request);
const response = await callback(request);
const responseLength = response.length;

@@ -79,5 +70,6 @@ int32[2] = responseLength;

this.serveAsync(callback);
}))().catch(() => { });
})().catch(() => { });
}
}
exports.SyncMessenger = SyncMessenger;
//# sourceMappingURL=SyncMessenger.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=types.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=types.js.map

@@ -33,5 +33,8 @@ import Stats from './Stats';

*/
export declare const memfs: (json?: NestedDirectoryJSON, cwd?: string) => IFs;
export declare const memfs: (json?: NestedDirectoryJSON, cwd?: string) => {
fs: IFs;
vol: _Volume;
};
export type IFsWithVolume = IFs & {
__vol: _Volume;
};

@@ -7,4 +7,5 @@ "use strict";

const volume_1 = require("./volume");
const { fsSyncMethods, fsAsyncMethods } = require('fs-monkey/lib/util/lists');
const constants_1 = require("./constants");
const fsSynchronousApiList_1 = require("./node/lists/fsSynchronousApiList");
const fsCallbackApiList_1 = require("./node/lists/fsCallbackApiList");
const { F_OK, R_OK, W_OK, X_OK } = constants_1.constants;

@@ -17,6 +18,6 @@ exports.Volume = volume_1.Volume;

// Bind FS methods.
for (const method of fsSyncMethods)
for (const method of fsSynchronousApiList_1.fsSynchronousApiList)
if (typeof vol[method] === 'function')
fs[method] = vol[method].bind(vol);
for (const method of fsAsyncMethods)
for (const method of fsCallbackApiList_1.fsCallbackApiList)
if (typeof vol[method] === 'function')

@@ -46,5 +47,5 @@ fs[method] = vol[method].bind(vol);

const memfs = (json = {}, cwd = '/') => {
const volume = exports.Volume.fromNestedJSON(json, cwd);
const fs = createFsFromVolume(volume);
return fs;
const vol = exports.Volume.fromNestedJSON(json, cwd);
const fs = createFsFromVolume(vol);
return { fs, vol };
};

@@ -54,1 +55,2 @@ exports.memfs = memfs;

module.exports.semantic = true;
//# sourceMappingURL=index.js.map

@@ -13,1 +13,2 @@ "use strict";

exports.bufferFrom = bufferFrom;
//# sourceMappingURL=buffer.js.map

@@ -236,1 +236,2 @@ "use strict";

}
//# sourceMappingURL=errors.js.map
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __asyncValues = (this && this.__asyncValues) || function (o) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var m = o[Symbol.asyncIterator], i;
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
};
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const __1 = require("../..");

@@ -24,3 +9,3 @@ const NodeFileSystemDirectoryHandle_1 = require("../NodeFileSystemDirectoryHandle");

const setup = (json = {}) => {
const fs = (0, __1.memfs)(json, '/');
const { fs } = (0, __1.memfs)(json, '/');
const dir = new NodeFileSystemDirectoryHandle_1.NodeFileSystemDirectoryHandle(fs, '/', { mode: 'readwrite' });

@@ -35,8 +20,8 @@ return { dir, fs };

describe('.keys()', () => {
test('returns an empty iterator for an empty directory', () => __awaiter(void 0, void 0, void 0, function* () {
test('returns an empty iterator for an empty directory', async () => {
const { dir } = setup();
const keys = dir.keys();
expect(yield keys.next()).toStrictEqual({ done: true, value: undefined });
}));
test('returns a folder', () => __awaiter(void 0, void 0, void 0, function* () {
expect(await keys.next()).toStrictEqual({ done: true, value: undefined });
});
test('returns a folder', async () => {
var _a, e_1, _b, _c;

@@ -46,12 +31,7 @@ const { dir } = setup({ folder: null });

try {
for (var _d = true, _e = __asyncValues(dir.keys()), _f; _f = yield _e.next(), _a = _f.done, !_a;) {
for (var _d = true, _e = tslib_1.__asyncValues(dir.keys()), _f; _f = await _e.next(), _a = _f.done, !_a; _d = true) {
_c = _f.value;
_d = false;
try {
const key = _c;
list.push(key);
}
finally {
_d = true;
}
const key = _c;
list.push(key);
}

@@ -62,3 +42,3 @@ }

try {
if (!_d && !_a && (_b = _e.return)) yield _b.call(_e);
if (!_d && !_a && (_b = _e.return)) await _b.call(_e);
}

@@ -68,5 +48,5 @@ finally { if (e_1) throw e_1.error; }

expect(list).toStrictEqual(['folder']);
}));
test('returns two folders', () => __awaiter(void 0, void 0, void 0, function* () {
var _g, e_2, _h, _j;
});
test('returns two folders', async () => {
var _a, e_2, _b, _c;
const { dir } = setup({

@@ -78,12 +58,7 @@ folder: null,

try {
for (var _k = true, _l = __asyncValues(dir.keys()), _m; _m = yield _l.next(), _g = _m.done, !_g;) {
_j = _m.value;
_k = false;
try {
const key = _j;
list.push(key);
}
finally {
_k = true;
}
for (var _d = true, _e = tslib_1.__asyncValues(dir.keys()), _f; _f = await _e.next(), _a = _f.done, !_a; _d = true) {
_c = _f.value;
_d = false;
const key = _c;
list.push(key);
}

@@ -94,3 +69,3 @@ }

try {
if (!_k && !_g && (_h = _l.return)) yield _h.call(_l);
if (!_d && !_a && (_b = _e.return)) await _b.call(_e);
}

@@ -100,5 +75,5 @@ finally { if (e_2) throw e_2.error; }

expect(list.length).toBe(2);
}));
test('returns a file', () => __awaiter(void 0, void 0, void 0, function* () {
var _o, e_3, _p, _q;
});
test('returns a file', async () => {
var _a, e_3, _b, _c;
const { dir } = setup({

@@ -109,12 +84,7 @@ 'file.txt': 'Hello, world!',

try {
for (var _r = true, _s = __asyncValues(dir.keys()), _t; _t = yield _s.next(), _o = _t.done, !_o;) {
_q = _t.value;
_r = false;
try {
const key = _q;
list.push(key);
}
finally {
_r = true;
}
for (var _d = true, _e = tslib_1.__asyncValues(dir.keys()), _f; _f = await _e.next(), _a = _f.done, !_a; _d = true) {
_c = _f.value;
_d = false;
const key = _c;
list.push(key);
}

@@ -125,3 +95,3 @@ }

try {
if (!_r && !_o && (_p = _s.return)) yield _p.call(_s);
if (!_d && !_a && (_b = _e.return)) await _b.call(_e);
}

@@ -131,27 +101,22 @@ finally { if (e_3) throw e_3.error; }

expect(list).toStrictEqual(['file.txt']);
}));
});
});
describe('.entries()', () => {
test('returns an empty iterator for an empty directory', () => __awaiter(void 0, void 0, void 0, function* () {
test('returns an empty iterator for an empty directory', async () => {
const { dir } = setup();
const keys = dir.entries();
expect(yield keys.next()).toStrictEqual({ done: true, value: undefined });
}));
test('returns a folder', () => __awaiter(void 0, void 0, void 0, function* () {
expect(await keys.next()).toStrictEqual({ done: true, value: undefined });
});
test('returns a folder', async () => {
var _a, e_4, _b, _c;
const { dir } = setup({ 'My Documents': null });
try {
for (var _d = true, _e = __asyncValues(dir.entries()), _f; _f = yield _e.next(), _a = _f.done, !_a;) {
for (var _d = true, _e = tslib_1.__asyncValues(dir.entries()), _f; _f = await _e.next(), _a = _f.done, !_a; _d = true) {
_c = _f.value;
_d = false;
try {
const [name, subdir] = _c;
expect(name).toBe('My Documents');
expect(subdir).toBeInstanceOf(NodeFileSystemDirectoryHandle_1.NodeFileSystemDirectoryHandle);
expect(subdir.kind).toBe('directory');
expect(subdir.name).toBe('My Documents');
}
finally {
_d = true;
}
const [name, subdir] = _c;
expect(name).toBe('My Documents');
expect(subdir).toBeInstanceOf(NodeFileSystemDirectoryHandle_1.NodeFileSystemDirectoryHandle);
expect(subdir.kind).toBe('directory');
expect(subdir.name).toBe('My Documents');
}

@@ -162,9 +127,9 @@ }

try {
if (!_d && !_a && (_b = _e.return)) yield _b.call(_e);
if (!_d && !_a && (_b = _e.return)) await _b.call(_e);
}
finally { if (e_4) throw e_4.error; }
}
}));
test('returns a file', () => __awaiter(void 0, void 0, void 0, function* () {
var _g, e_5, _h, _j;
});
test('returns a file', async () => {
var _a, e_5, _b, _c;
const { dir } = setup({

@@ -174,15 +139,10 @@ 'file.txt': 'Hello, world!',

try {
for (var _k = true, _l = __asyncValues(dir.entries()), _m; _m = yield _l.next(), _g = _m.done, !_g;) {
_j = _m.value;
_k = false;
try {
const [name, file] = _j;
expect(name).toBe('file.txt');
expect(file).toBeInstanceOf(NodeFileSystemFileHandle_1.NodeFileSystemFileHandle);
expect(file.kind).toBe('file');
expect(file.name).toBe('file.txt');
}
finally {
_k = true;
}
for (var _d = true, _e = tslib_1.__asyncValues(dir.entries()), _f; _f = await _e.next(), _a = _f.done, !_a; _d = true) {
_c = _f.value;
_d = false;
const [name, file] = _c;
expect(name).toBe('file.txt');
expect(file).toBeInstanceOf(NodeFileSystemFileHandle_1.NodeFileSystemFileHandle);
expect(file.kind).toBe('file');
expect(file.name).toBe('file.txt');
}

@@ -193,9 +153,9 @@ }

try {
if (!_k && !_g && (_h = _l.return)) yield _h.call(_l);
if (!_d && !_a && (_b = _e.return)) await _b.call(_e);
}
finally { if (e_5) throw e_5.error; }
}
}));
test('returns two entries', () => __awaiter(void 0, void 0, void 0, function* () {
var _o, e_6, _p, _q;
});
test('returns two entries', async () => {
var _a, e_6, _b, _c;
const { dir } = setup({

@@ -207,12 +167,7 @@ 'index.html': '<nobr>Hello, world!</nobr>',

try {
for (var _r = true, _s = __asyncValues(dir.entries()), _t; _t = yield _s.next(), _o = _t.done, !_o;) {
_q = _t.value;
_r = false;
try {
const entry = _q;
handles.push(entry[1]);
}
finally {
_r = true;
}
for (var _d = true, _e = tslib_1.__asyncValues(dir.entries()), _f; _f = await _e.next(), _a = _f.done, !_a; _d = true) {
_c = _f.value;
_d = false;
const entry = _c;
handles.push(entry[1]);
}

@@ -223,3 +178,3 @@ }

try {
if (!_r && !_o && (_p = _s.return)) yield _p.call(_s);
if (!_d && !_a && (_b = _e.return)) await _b.call(_e);
}

@@ -231,26 +186,21 @@ finally { if (e_6) throw e_6.error; }

expect(handles.find(handle => handle.name === 'another')).toBeInstanceOf(NodeFileSystemDirectoryHandle_1.NodeFileSystemDirectoryHandle);
}));
});
});
describe('.values()', () => {
test('returns an empty iterator for an empty directory', () => __awaiter(void 0, void 0, void 0, function* () {
test('returns an empty iterator for an empty directory', async () => {
const { dir } = setup();
const values = dir.values();
expect(yield values.next()).toStrictEqual({ done: true, value: undefined });
}));
test('returns a folder', () => __awaiter(void 0, void 0, void 0, function* () {
expect(await values.next()).toStrictEqual({ done: true, value: undefined });
});
test('returns a folder', async () => {
var _a, e_7, _b, _c;
const { dir } = setup({ 'My Documents': null });
try {
for (var _d = true, _e = __asyncValues(dir.values()), _f; _f = yield _e.next(), _a = _f.done, !_a;) {
for (var _d = true, _e = tslib_1.__asyncValues(dir.values()), _f; _f = await _e.next(), _a = _f.done, !_a; _d = true) {
_c = _f.value;
_d = false;
try {
const subdir = _c;
expect(subdir).toBeInstanceOf(NodeFileSystemDirectoryHandle_1.NodeFileSystemDirectoryHandle);
expect(subdir.kind).toBe('directory');
expect(subdir.name).toBe('My Documents');
}
finally {
_d = true;
}
const subdir = _c;
expect(subdir).toBeInstanceOf(NodeFileSystemDirectoryHandle_1.NodeFileSystemDirectoryHandle);
expect(subdir.kind).toBe('directory');
expect(subdir.name).toBe('My Documents');
}

@@ -261,9 +211,9 @@ }

try {
if (!_d && !_a && (_b = _e.return)) yield _b.call(_e);
if (!_d && !_a && (_b = _e.return)) await _b.call(_e);
}
finally { if (e_7) throw e_7.error; }
}
}));
test('returns a file', () => __awaiter(void 0, void 0, void 0, function* () {
var _g, e_8, _h, _j;
});
test('returns a file', async () => {
var _a, e_8, _b, _c;
const { dir } = setup({

@@ -273,14 +223,9 @@ 'file.txt': 'Hello, world!',

try {
for (var _k = true, _l = __asyncValues(dir.values()), _m; _m = yield _l.next(), _g = _m.done, !_g;) {
_j = _m.value;
_k = false;
try {
const file = _j;
expect(file).toBeInstanceOf(NodeFileSystemFileHandle_1.NodeFileSystemFileHandle);
expect(file.kind).toBe('file');
expect(file.name).toBe('file.txt');
}
finally {
_k = true;
}
for (var _d = true, _e = tslib_1.__asyncValues(dir.values()), _f; _f = await _e.next(), _a = _f.done, !_a; _d = true) {
_c = _f.value;
_d = false;
const file = _c;
expect(file).toBeInstanceOf(NodeFileSystemFileHandle_1.NodeFileSystemFileHandle);
expect(file.kind).toBe('file');
expect(file.name).toBe('file.txt');
}

@@ -291,9 +236,9 @@ }

try {
if (!_k && !_g && (_h = _l.return)) yield _h.call(_l);
if (!_d && !_a && (_b = _e.return)) await _b.call(_e);
}
finally { if (e_8) throw e_8.error; }
}
}));
test('returns two entries', () => __awaiter(void 0, void 0, void 0, function* () {
var _o, e_9, _p, _q;
});
test('returns two entries', async () => {
var _a, e_9, _b, _c;
const { dir } = setup({

@@ -305,12 +250,7 @@ 'index.html': '<nobr>Hello, world!</nobr>',

try {
for (var _r = true, _s = __asyncValues(dir.values()), _t; _t = yield _s.next(), _o = _t.done, !_o;) {
_q = _t.value;
_r = false;
try {
const entry = _q;
handles.push(entry);
}
finally {
_r = true;
}
for (var _d = true, _e = tslib_1.__asyncValues(dir.values()), _f; _f = await _e.next(), _a = _f.done, !_a; _d = true) {
_c = _f.value;
_d = false;
const entry = _c;
handles.push(entry);
}

@@ -321,3 +261,3 @@ }

try {
if (!_r && !_o && (_p = _s.return)) yield _p.call(_s);
if (!_d && !_a && (_b = _e.return)) await _b.call(_e);
}

@@ -329,9 +269,9 @@ finally { if (e_9) throw e_9.error; }

expect(handles.find(handle => handle.name === 'another')).toBeInstanceOf(NodeFileSystemDirectoryHandle_1.NodeFileSystemDirectoryHandle);
}));
});
});
describe('.getDirectoryHandle()', () => {
test('throws "NotFoundError" DOMException if sub-directory not found', () => __awaiter(void 0, void 0, void 0, function* () {
test('throws "NotFoundError" DOMException if sub-directory not found', async () => {
const { dir } = setup({ a: null });
try {
yield dir.getDirectoryHandle('b');
await dir.getDirectoryHandle('b');
throw new Error('Not this error.');

@@ -344,7 +284,7 @@ }

}
}));
test('throws "TypeMismatchError" DOMException if entry is not a directory', () => __awaiter(void 0, void 0, void 0, function* () {
});
test('throws "TypeMismatchError" DOMException if entry is not a directory', async () => {
const { dir } = setup({ file: 'contents' });
try {
yield dir.getDirectoryHandle('file');
await dir.getDirectoryHandle('file');
throw new Error('Not this error.');

@@ -357,8 +297,8 @@ }

}
}));
test('throws if not in "readwrite" mode and attempting to create a directory', () => __awaiter(void 0, void 0, void 0, function* () {
const fs = (0, __1.memfs)({}, '/');
});
test('throws if not in "readwrite" mode and attempting to create a directory', async () => {
const { fs } = (0, __1.memfs)({}, '/');
const dir = new NodeFileSystemDirectoryHandle_1.NodeFileSystemDirectoryHandle(fs, '/', { mode: 'read' });
try {
yield dir.getDirectoryHandle('test', { create: true });
await dir.getDirectoryHandle('test', { create: true });
throw new Error('Not this error');

@@ -371,3 +311,3 @@ }

}
}));
});
const invalidNames = [

@@ -391,6 +331,6 @@ '.',

for (const invalidName of invalidNames) {
test(`throws on invalid file name: "${invalidName}"`, () => __awaiter(void 0, void 0, void 0, function* () {
test(`throws on invalid file name: "${invalidName}"`, async () => {
const { dir } = setup({ file: 'contents' });
try {
yield dir.getDirectoryHandle(invalidName);
await dir.getDirectoryHandle(invalidName);
throw new Error('Not this error.');

@@ -402,15 +342,15 @@ }

}
}));
});
}
test('can retrieve a child directory', () => __awaiter(void 0, void 0, void 0, function* () {
test('can retrieve a child directory', async () => {
const { dir } = setup({ file: 'contents', subdir: null });
const subdir = yield dir.getDirectoryHandle('subdir');
const subdir = await dir.getDirectoryHandle('subdir');
expect(subdir.kind).toBe('directory');
expect(subdir.name).toBe('subdir');
expect(subdir).toBeInstanceOf(NodeFileSystemDirectoryHandle_1.NodeFileSystemDirectoryHandle);
}));
test('can create a sub-directory', () => __awaiter(void 0, void 0, void 0, function* () {
});
test('can create a sub-directory', async () => {
const { dir, fs } = setup({});
expect(fs.existsSync('/subdir')).toBe(false);
const subdir = yield dir.getDirectoryHandle('subdir', { create: true });
const subdir = await dir.getDirectoryHandle('subdir', { create: true });
expect(fs.existsSync('/subdir')).toBe(true);

@@ -421,9 +361,9 @@ expect(fs.statSync('/subdir').isDirectory()).toBe(true);

expect(subdir).toBeInstanceOf(NodeFileSystemDirectoryHandle_1.NodeFileSystemDirectoryHandle);
}));
});
});
describe('.getFileHandle()', () => {
test('throws "NotFoundError" DOMException if file not found', () => __awaiter(void 0, void 0, void 0, function* () {
test('throws "NotFoundError" DOMException if file not found', async () => {
const { dir } = setup({ a: null });
try {
yield dir.getFileHandle('b');
await dir.getFileHandle('b');
throw new Error('Not this error.');

@@ -436,7 +376,7 @@ }

}
}));
test('throws "TypeMismatchError" DOMException if entry is not a file', () => __awaiter(void 0, void 0, void 0, function* () {
});
test('throws "TypeMismatchError" DOMException if entry is not a file', async () => {
const { dir } = setup({ directory: null });
try {
yield dir.getFileHandle('directory');
await dir.getFileHandle('directory');
throw new Error('Not this error.');

@@ -449,8 +389,8 @@ }

}
}));
test('throws if not in "readwrite" mode and attempting to create a file', () => __awaiter(void 0, void 0, void 0, function* () {
const fs = (0, __1.memfs)({}, '/');
});
test('throws if not in "readwrite" mode and attempting to create a file', async () => {
const { fs } = (0, __1.memfs)({}, '/');
const dir = new NodeFileSystemDirectoryHandle_1.NodeFileSystemDirectoryHandle(fs, '/', { mode: 'read' });
try {
yield dir.getFileHandle('test', { create: true });
await dir.getFileHandle('test', { create: true });
throw new Error('Not this error');

@@ -463,3 +403,3 @@ }

}
}));
});
const invalidNames = [

@@ -484,6 +424,6 @@ '',

for (const invalidName of invalidNames) {
test(`throws on invalid file name: "${invalidName}"`, () => __awaiter(void 0, void 0, void 0, function* () {
test(`throws on invalid file name: "${invalidName}"`, async () => {
const { dir } = setup({ file: 'contents' });
try {
yield dir.getFileHandle(invalidName);
await dir.getFileHandle(invalidName);
throw new Error('Not this error.');

@@ -495,15 +435,15 @@ }

}
}));
});
}
test('can retrieve a child file', () => __awaiter(void 0, void 0, void 0, function* () {
test('can retrieve a child file', async () => {
const { dir } = setup({ file: 'contents', subdir: null });
const subdir = yield dir.getFileHandle('file');
const subdir = await dir.getFileHandle('file');
expect(subdir.kind).toBe('file');
expect(subdir.name).toBe('file');
expect(subdir).toBeInstanceOf(NodeFileSystemFileHandle_1.NodeFileSystemFileHandle);
}));
test('can create a file', () => __awaiter(void 0, void 0, void 0, function* () {
});
test('can create a file', async () => {
const { dir, fs } = setup({});
expect(fs.existsSync('/text.txt')).toBe(false);
const subdir = yield dir.getFileHandle('text.txt', { create: true });
const subdir = await dir.getFileHandle('text.txt', { create: true });
expect(fs.existsSync('/text.txt')).toBe(true);

@@ -514,9 +454,9 @@ expect(fs.statSync('/text.txt').isFile()).toBe(true);

expect(subdir).toBeInstanceOf(NodeFileSystemFileHandle_1.NodeFileSystemFileHandle);
}));
});
});
describe('.removeEntry()', () => {
test('throws "NotFoundError" DOMException if file not found', () => __awaiter(void 0, void 0, void 0, function* () {
test('throws "NotFoundError" DOMException if file not found', async () => {
const { dir } = setup({ a: null });
try {
yield dir.removeEntry('b');
await dir.removeEntry('b');
throw new Error('Not this error.');

@@ -529,8 +469,8 @@ }

}
}));
test('throws if not in "readwrite" mode and attempting to remove a file', () => __awaiter(void 0, void 0, void 0, function* () {
const fs = (0, __1.memfs)({ a: 'b' }, '/');
});
test('throws if not in "readwrite" mode and attempting to remove a file', async () => {
const { fs } = (0, __1.memfs)({ a: 'b' }, '/');
const dir = new NodeFileSystemDirectoryHandle_1.NodeFileSystemDirectoryHandle(fs, '/', { mode: 'read' });
try {
yield dir.removeEntry('a');
await dir.removeEntry('a');
throw new Error('Not this error');

@@ -543,8 +483,8 @@ }

}
}));
test('throws if not in "readwrite" mode and attempting to remove a folder', () => __awaiter(void 0, void 0, void 0, function* () {
const fs = (0, __1.memfs)({ a: null }, '/');
});
test('throws if not in "readwrite" mode and attempting to remove a folder', async () => {
const { fs } = (0, __1.memfs)({ a: null }, '/');
const dir = new NodeFileSystemDirectoryHandle_1.NodeFileSystemDirectoryHandle(fs, '/', { mode: 'read' });
try {
yield dir.removeEntry('a');
await dir.removeEntry('a');
throw new Error('Not this error');

@@ -557,3 +497,3 @@ }

}
}));
});
const invalidNames = [

@@ -578,6 +518,6 @@ '',

for (const invalidName of invalidNames) {
test(`throws on invalid file name: "${invalidName}"`, () => __awaiter(void 0, void 0, void 0, function* () {
test(`throws on invalid file name: "${invalidName}"`, async () => {
const { dir } = setup({ file: 'contents' });
try {
yield dir.removeEntry(invalidName);
await dir.removeEntry(invalidName);
throw new Error('Not this error.');

@@ -589,19 +529,19 @@ }

}
}));
});
}
test('can delete a file', () => __awaiter(void 0, void 0, void 0, function* () {
test('can delete a file', async () => {
const { dir, fs } = setup({ file: 'contents', subdir: null });
expect(fs.statSync('/file').isFile()).toBe(true);
const res = yield dir.removeEntry('file');
const res = await dir.removeEntry('file');
expect(fs.existsSync('/file')).toBe(false);
expect(res).toBe(undefined);
}));
test('can delete a folder', () => __awaiter(void 0, void 0, void 0, function* () {
});
test('can delete a folder', async () => {
const { dir, fs } = setup({ dir: null });
expect(fs.statSync('/dir').isDirectory()).toBe(true);
const res = yield dir.removeEntry('dir');
const res = await dir.removeEntry('dir');
expect(fs.existsSync('/dir')).toBe(false);
expect(res).toBe(undefined);
}));
test('throws "InvalidModificationError" DOMException if directory has contents', () => __awaiter(void 0, void 0, void 0, function* () {
});
test('throws "InvalidModificationError" DOMException if directory has contents', async () => {
const { dir, fs } = setup({

@@ -613,3 +553,3 @@ 'dir/file': 'contents',

try {
res = yield dir.removeEntry('dir');
res = await dir.removeEntry('dir');
throw new Error('Not this error.');

@@ -623,4 +563,4 @@ }

}
}));
test('can recursively delete a folder with "recursive" flag', () => __awaiter(void 0, void 0, void 0, function* () {
});
test('can recursively delete a folder with "recursive" flag', async () => {
const { dir, fs } = setup({

@@ -630,41 +570,42 @@ 'dir/file': 'contents',

expect(fs.statSync('/dir').isDirectory()).toBe(true);
const res = yield dir.removeEntry('dir', { recursive: true });
const res = await dir.removeEntry('dir', { recursive: true });
expect(fs.existsSync('/dir')).toBe(false);
expect(res).toBe(undefined);
}));
});
});
describe('.resolve()', () => {
test('return empty array for itself', () => __awaiter(void 0, void 0, void 0, function* () {
test('return empty array for itself', async () => {
const { dir } = setup({});
const res = yield dir.resolve(dir);
const res = await dir.resolve(dir);
expect(res).toStrictEqual([]);
}));
test('can resolve one level deep child', () => __awaiter(void 0, void 0, void 0, function* () {
});
test('can resolve one level deep child', async () => {
const { dir } = setup({
file: 'contents',
});
const child = yield dir.getFileHandle('file');
const res = yield dir.resolve(child);
const child = await dir.getFileHandle('file');
const res = await dir.resolve(child);
expect(res).toStrictEqual(['file']);
}));
test('can resolve two level deep child', () => __awaiter(void 0, void 0, void 0, function* () {
});
test('can resolve two level deep child', async () => {
const { dir } = setup({
'dir/file': 'contents',
});
const child1 = yield dir.getDirectoryHandle('dir');
const child2 = yield child1.getFileHandle('file');
const res = yield dir.resolve(child2);
const child1 = await dir.getDirectoryHandle('dir');
const child2 = await child1.getFileHandle('file');
const res = await dir.resolve(child2);
expect(res).toStrictEqual(['dir', 'file']);
const res2 = yield child1.resolve(child2);
const res2 = await child1.resolve(child2);
expect(res2).toStrictEqual(['file']);
}));
test('returns "null" if not a descendant', () => __awaiter(void 0, void 0, void 0, function* () {
});
test('returns "null" if not a descendant', async () => {
const { dir } = setup({
'dir/file': 'contents',
});
const child1 = yield dir.getDirectoryHandle('dir');
const res = yield child1.resolve(dir);
const child1 = await dir.getDirectoryHandle('dir');
const res = await child1.resolve(dir);
expect(res).toBe(null);
}));
});
});
});
//# sourceMappingURL=NodeFileSystemDirectoryHandle.test.js.map
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -16,15 +7,15 @@ const __1 = require("../..");

const setup = (json = {}) => {
const fs = (0, __1.memfs)(json, '/');
const { fs, vol } = (0, __1.memfs)(json, '/');
const dir = new NodeFileSystemDirectoryHandle_1.NodeFileSystemDirectoryHandle(fs, '/', { mode: 'readwrite' });
return { dir, fs };
return { dir, fs, vol };
};
(0, util_1.onlyOnNode20)('NodeFileSystemFileHandle', () => {
describe('.getFile()', () => {
test('can read file contents', () => __awaiter(void 0, void 0, void 0, function* () {
test('can read file contents', async () => {
const { dir, fs } = setup({
'file.txt': 'Hello, world!',
});
const entry = yield dir.getFileHandle('file.txt');
const file = yield entry.getFile();
const contents = yield file.text();
const entry = await dir.getFileHandle('file.txt');
const file = await entry.getFile();
const contents = await file.text();
expect(entry.name).toBe('file.txt');

@@ -35,11 +26,11 @@ expect(file).toBeInstanceOf(File);

expect(contents).toBe('Hello, world!');
}));
});
});
describe('.createWritable()', () => {
test('throws if not in "readwrite" mode', () => __awaiter(void 0, void 0, void 0, function* () {
const fs = (0, __1.memfs)({ 'file.txt': 'abc' }, '/');
test('throws if not in "readwrite" mode', async () => {
const { fs } = (0, __1.memfs)({ 'file.txt': 'abc' }, '/');
const dir = new NodeFileSystemDirectoryHandle_1.NodeFileSystemDirectoryHandle(fs, '/', { mode: 'read' });
const entry = yield dir.getFileHandle('file.txt');
const entry = await dir.getFileHandle('file.txt');
try {
yield entry.createWritable();
await entry.createWritable();
throw new Error('Not this error');

@@ -52,143 +43,144 @@ }

}
}));
});
describe('.truncate()', () => {
test('can truncate file', () => __awaiter(void 0, void 0, void 0, function* () {
test('can truncate file', async () => {
const { dir, fs } = setup({
'file.txt': '012345',
});
const entry = yield dir.getFileHandle('file.txt');
const writable = yield entry.createWritable({ keepExistingData: true });
yield writable.truncate(3);
yield writable.close();
const entry = await dir.getFileHandle('file.txt');
const writable = await entry.createWritable({ keepExistingData: true });
await writable.truncate(3);
await writable.close();
expect(fs.readFileSync('/file.txt', 'utf8')).toBe('012');
}));
test('can truncate file - 2', () => __awaiter(void 0, void 0, void 0, function* () {
});
test('can truncate file - 2', async () => {
const { dir, fs } = setup({
'file.txt': '012345',
});
const entry = yield dir.getFileHandle('file.txt');
const writable = yield entry.createWritable({ keepExistingData: true });
yield writable.write({ type: 'truncate', size: 3 });
yield writable.close();
const entry = await dir.getFileHandle('file.txt');
const writable = await entry.createWritable({ keepExistingData: true });
await writable.write({ type: 'truncate', size: 3 });
await writable.close();
expect(fs.readFileSync('/file.txt', 'utf8')).toBe('012');
}));
test('can truncate up', () => __awaiter(void 0, void 0, void 0, function* () {
});
test('can truncate up', async () => {
const { dir, fs } = setup({
'file.txt': '012345',
});
const entry = yield dir.getFileHandle('file.txt');
const writable = yield entry.createWritable({ keepExistingData: true });
yield writable.write({ type: 'truncate', size: 10 });
yield writable.close();
const entry = await dir.getFileHandle('file.txt');
const writable = await entry.createWritable({ keepExistingData: true });
await writable.write({ type: 'truncate', size: 10 });
await writable.close();
expect(fs.readFileSync('/file.txt').length).toBe(10);
expect(fs.readFileSync('/file.txt')[8]).toBe(0);
}));
test('on up truncation bytes are nulled', () => __awaiter(void 0, void 0, void 0, function* () {
});
test('on up truncation bytes are nulled', async () => {
const { dir, fs } = setup({
'file.txt': '012345',
});
const entry = yield dir.getFileHandle('file.txt');
const writable = yield entry.createWritable({ keepExistingData: true });
yield writable.write({ type: 'truncate', size: 10 });
yield writable.close();
const entry = await dir.getFileHandle('file.txt');
const writable = await entry.createWritable({ keepExistingData: true });
await writable.write({ type: 'truncate', size: 10 });
await writable.close();
expect(fs.readFileSync('/file.txt')[8]).toBe(0);
}));
});
});
describe('.write(chunk)', () => {
test('overwrites the file when write is being executed', () => __awaiter(void 0, void 0, void 0, function* () {
test('overwrites the file when write is being executed', async () => {
const { dir, fs } = setup({
'file.txt': 'Hello, world!',
});
const entry = yield dir.getFileHandle('file.txt');
const writable = yield entry.createWritable();
yield writable.write('...');
yield writable.close();
const entry = await dir.getFileHandle('file.txt');
const writable = await entry.createWritable();
await writable.write('...');
await writable.close();
expect(fs.readFileSync('/file.txt', 'utf8')).toBe('...');
}));
test('writes at file start', () => __awaiter(void 0, void 0, void 0, function* () {
});
test('writes at file start', async () => {
const { dir, fs } = setup({
'file.txt': '...',
});
const entry = yield dir.getFileHandle('file.txt');
const writable = yield entry.createWritable({ keepExistingData: true });
yield writable.write('1');
yield writable.close();
const entry = await dir.getFileHandle('file.txt');
const writable = await entry.createWritable({ keepExistingData: true });
await writable.write('1');
await writable.close();
expect(fs.readFileSync('/file.txt', 'utf8')).toBe('1..');
}));
test('can seek and then write', () => __awaiter(void 0, void 0, void 0, function* () {
});
test('can seek and then write', async () => {
const { dir, fs } = setup({
'file.txt': '...',
});
const entry = yield dir.getFileHandle('file.txt');
const writable = yield entry.createWritable({ keepExistingData: true });
const entry = await dir.getFileHandle('file.txt');
const writable = await entry.createWritable({ keepExistingData: true });
writable.seek(1);
yield writable.write('1');
yield writable.write('2');
await writable.write('1');
await writable.write('2');
expect(fs.readFileSync('/file.txt', 'utf8')).toBe('...');
yield writable.close();
await writable.close();
expect(fs.readFileSync('/file.txt', 'utf8')).toBe('.12');
}));
test('does not commit changes before .close() is called', () => __awaiter(void 0, void 0, void 0, function* () {
});
test('does not commit changes before .close() is called', async () => {
const { dir, fs } = setup({
'file.txt': '...',
});
const entry = yield dir.getFileHandle('file.txt');
const writable = yield entry.createWritable();
yield writable.write('1');
const entry = await dir.getFileHandle('file.txt');
const writable = await entry.createWritable();
await writable.write('1');
expect(fs.readFileSync('/file.txt', 'utf8')).toBe('...');
yield writable.close();
await writable.close();
expect(fs.readFileSync('/file.txt', 'utf8')).toBe('1');
}));
test('does not commit changes if .abort() is called and removes the swap file', () => __awaiter(void 0, void 0, void 0, function* () {
const { dir, fs } = setup({
});
test('does not commit changes if .abort() is called and removes the swap file', async () => {
const { dir, vol } = setup({
'file.txt': '...',
});
const entry = yield dir.getFileHandle('file.txt');
const writable = yield entry.createWritable();
yield writable.write('1');
expect(fs.__vol.toJSON()).toStrictEqual({
const entry = await dir.getFileHandle('file.txt');
const writable = await entry.createWritable();
await writable.write('1');
expect(vol.toJSON()).toStrictEqual({
'/file.txt': '...',
'/file.txt.crswap': '1',
});
yield writable.abort();
expect(fs.__vol.toJSON()).toStrictEqual({
await writable.abort();
expect(vol.toJSON()).toStrictEqual({
'/file.txt': '...',
});
}));
});
});
describe('.write(options)', () => {
test('can write at offset, when providing position in write call', () => __awaiter(void 0, void 0, void 0, function* () {
test('can write at offset, when providing position in write call', async () => {
const { dir, fs } = setup({
'file.txt': '...',
});
const entry = yield dir.getFileHandle('file.txt');
const writable = yield entry.createWritable({ keepExistingData: true });
yield writable.write({ type: 'write', position: 1, data: '1' });
yield writable.close();
const entry = await dir.getFileHandle('file.txt');
const writable = await entry.createWritable({ keepExistingData: true });
await writable.write({ type: 'write', position: 1, data: '1' });
await writable.close();
expect(fs.readFileSync('/file.txt', 'utf8')).toBe('.1.');
}));
test('can seek and then write', () => __awaiter(void 0, void 0, void 0, function* () {
});
test('can seek and then write', async () => {
const { dir, fs } = setup({
'file.txt': '...',
});
const entry = yield dir.getFileHandle('file.txt');
const writable = yield entry.createWritable({ keepExistingData: true });
yield writable.write({ type: 'seek', position: 1 });
yield writable.write({ type: 'write', data: Buffer.from('1') });
yield writable.close();
const entry = await dir.getFileHandle('file.txt');
const writable = await entry.createWritable({ keepExistingData: true });
await writable.write({ type: 'seek', position: 1 });
await writable.write({ type: 'write', data: Buffer.from('1') });
await writable.close();
expect(fs.readFileSync('/file.txt', 'utf8')).toBe('.1.');
}));
test('can seek and then write', () => __awaiter(void 0, void 0, void 0, function* () {
});
test('can seek and then write', async () => {
const { dir, fs } = setup({
'file.txt': '...',
});
const entry = yield dir.getFileHandle('file.txt');
const writable = yield entry.createWritable({ keepExistingData: true });
yield writable.write({ type: 'seek', position: 1 });
yield writable.write({ type: 'write', data: Buffer.from('1') });
yield writable.close();
const entry = await dir.getFileHandle('file.txt');
const writable = await entry.createWritable({ keepExistingData: true });
await writable.write({ type: 'seek', position: 1 });
await writable.write({ type: 'write', data: Buffer.from('1') });
await writable.close();
expect(fs.readFileSync('/file.txt', 'utf8')).toBe('.1.');
}));
});
});
});
});
//# sourceMappingURL=NodeFileSystemFileHandle.test.js.map
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -16,3 +7,3 @@ const __1 = require("../..");

const setup = (json = {}) => {
const fs = (0, __1.memfs)(json, '/');
const { fs } = (0, __1.memfs)(json, '/');
const dir = new NodeFileSystemDirectoryHandle_1.NodeFileSystemDirectoryHandle(fs, '/', { mode: 'readwrite' });

@@ -27,11 +18,11 @@ return { dir, fs };

describe('.isSameEntry()', () => {
test('returns true for the same root entry', () => __awaiter(void 0, void 0, void 0, function* () {
test('returns true for the same root entry', async () => {
const { dir } = setup();
expect(dir.isSameEntry(dir)).toBe(true);
}));
test('returns true for two different instances of the same entry', () => __awaiter(void 0, void 0, void 0, function* () {
});
test('returns true for two different instances of the same entry', async () => {
const { dir } = setup({
subdir: null,
});
const subdir = yield dir.getDirectoryHandle('subdir');
const subdir = await dir.getDirectoryHandle('subdir');
expect(subdir.isSameEntry(subdir)).toBe(true);

@@ -41,12 +32,13 @@ expect(dir.isSameEntry(dir)).toBe(true);

expect(subdir.isSameEntry(dir)).toBe(false);
}));
test('returns false when comparing file with a directory', () => __awaiter(void 0, void 0, void 0, function* () {
});
test('returns false when comparing file with a directory', async () => {
const { dir } = setup({
file: 'lala',
});
const file = yield dir.getFileHandle('file');
const file = await dir.getFileHandle('file');
expect(file.isSameEntry(dir)).toBe(false);
expect(dir.isSameEntry(file)).toBe(false);
}));
});
});
});
//# sourceMappingURL=NodeFileSystemHandle.test.js.map
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -17,3 +8,3 @@ const __1 = require("../..");

const setup = (json = {}) => {
const fs = (0, __1.memfs)(json, '/');
const { fs } = (0, __1.memfs)(json, '/');
const dir = new NodeFileSystemDirectoryHandle_1.NodeFileSystemDirectoryHandle(fs, '/', { syncHandleAllowed: true, mode: 'readwrite' });

@@ -24,89 +15,89 @@ return { dir, fs };

describe('.close()', () => {
test('can close the file', () => __awaiter(void 0, void 0, void 0, function* () {
test('can close the file', async () => {
const { dir } = setup({
'file.txt': 'Hello, world!',
});
const entry = yield dir.getFileHandle('file.txt');
const sync = yield entry.createSyncAccessHandle();
const entry = await dir.getFileHandle('file.txt');
const sync = await entry.createSyncAccessHandle();
expect(sync).toBeInstanceOf(NodeFileSystemSyncAccessHandle_1.NodeFileSystemSyncAccessHandle);
yield sync.close();
await sync.close();
// ...
}));
});
});
describe('.flush()', () => {
test('can flush', () => __awaiter(void 0, void 0, void 0, function* () {
test('can flush', async () => {
const { dir } = setup({
'file.txt': 'Hello, world!',
});
const entry = yield dir.getFileHandle('file.txt');
const sync = yield entry.createSyncAccessHandle();
yield sync.flush();
}));
const entry = await dir.getFileHandle('file.txt');
const sync = await entry.createSyncAccessHandle();
await sync.flush();
});
});
describe('.getSize()', () => {
test('can get file size', () => __awaiter(void 0, void 0, void 0, function* () {
test('can get file size', async () => {
const { dir } = setup({
'file.txt': 'Hello, world!',
});
const entry = yield dir.getFileHandle('file.txt');
const sync = yield entry.createSyncAccessHandle();
const size = yield sync.getSize();
const entry = await dir.getFileHandle('file.txt');
const sync = await entry.createSyncAccessHandle();
const size = await sync.getSize();
expect(size).toBe(13);
}));
});
});
describe('.getSize()', () => {
test('can get file size', () => __awaiter(void 0, void 0, void 0, function* () {
test('can get file size', async () => {
const { dir } = setup({
'file.txt': 'Hello, world!',
});
const entry = yield dir.getFileHandle('file.txt');
const sync = yield entry.createSyncAccessHandle();
const size = yield sync.getSize();
const entry = await dir.getFileHandle('file.txt');
const sync = await entry.createSyncAccessHandle();
const size = await sync.getSize();
expect(size).toBe(13);
}));
});
});
describe('.read()', () => {
test('can read from beginning', () => __awaiter(void 0, void 0, void 0, function* () {
test('can read from beginning', async () => {
const { dir } = setup({
'file.txt': '0123456789',
});
const entry = yield dir.getFileHandle('file.txt');
const sync = yield entry.createSyncAccessHandle();
const entry = await dir.getFileHandle('file.txt');
const sync = await entry.createSyncAccessHandle();
const buf = new Uint8Array(5);
const size = yield sync.read(buf);
const size = await sync.read(buf);
expect(size).toBe(5);
expect(Buffer.from(buf).toString()).toBe('01234');
}));
test('can read at offset', () => __awaiter(void 0, void 0, void 0, function* () {
});
test('can read at offset', async () => {
const { dir } = setup({
'file.txt': '0123456789',
});
const entry = yield dir.getFileHandle('file.txt');
const sync = yield entry.createSyncAccessHandle();
const entry = await dir.getFileHandle('file.txt');
const sync = await entry.createSyncAccessHandle();
const buf = new Uint8Array(3);
const size = yield sync.read(buf, { at: 3 });
const size = await sync.read(buf, { at: 3 });
expect(size).toBe(3);
expect(Buffer.from(buf).toString()).toBe('345');
}));
test('can read into buffer larger than file', () => __awaiter(void 0, void 0, void 0, function* () {
});
test('can read into buffer larger than file', async () => {
const { dir } = setup({
'file.txt': '0123456789',
});
const entry = yield dir.getFileHandle('file.txt');
const sync = yield entry.createSyncAccessHandle();
const entry = await dir.getFileHandle('file.txt');
const sync = await entry.createSyncAccessHandle();
const buf = new Uint8Array(25);
const size = yield sync.read(buf);
const size = await sync.read(buf);
expect(size).toBe(10);
expect(Buffer.from(buf).slice(0, 10).toString()).toBe('0123456789');
}));
test('throws "InvalidStateError" DOMException if handle is closed', () => __awaiter(void 0, void 0, void 0, function* () {
});
test('throws "InvalidStateError" DOMException if handle is closed', async () => {
const { dir } = setup({
'file.txt': '0123456789',
});
const entry = yield dir.getFileHandle('file.txt');
const sync = yield entry.createSyncAccessHandle();
yield sync.close();
const entry = await dir.getFileHandle('file.txt');
const sync = await entry.createSyncAccessHandle();
await sync.close();
const buf = new Uint8Array(25);
try {
const size = yield sync.read(buf);
const size = await sync.read(buf);
throw new Error('No error was thrown');

@@ -118,46 +109,46 @@ }

}
}));
});
});
describe('.truncate()', () => {
test('can read from beginning', () => __awaiter(void 0, void 0, void 0, function* () {
test('can read from beginning', async () => {
const { dir } = setup({
'file.txt': '0123456789',
});
const entry = yield dir.getFileHandle('file.txt');
const sync = yield entry.createSyncAccessHandle();
const res = yield sync.truncate(5);
const entry = await dir.getFileHandle('file.txt');
const sync = await entry.createSyncAccessHandle();
const res = await sync.truncate(5);
expect(res).toBe(undefined);
}));
});
});
describe('.write()', () => {
test('can write to the file', () => __awaiter(void 0, void 0, void 0, function* () {
test('can write to the file', async () => {
const { dir, fs } = setup({
'file.txt': '0123456789',
});
const entry = yield dir.getFileHandle('file.txt');
const sync = yield entry.createSyncAccessHandle();
const res = yield sync.write(Buffer.from('Hello'));
const entry = await dir.getFileHandle('file.txt');
const sync = await entry.createSyncAccessHandle();
const res = await sync.write(Buffer.from('Hello'));
expect(res).toBe(5);
expect(fs.readFileSync('/file.txt', 'utf8')).toBe('Hello56789');
}));
test('can write at an offset', () => __awaiter(void 0, void 0, void 0, function* () {
});
test('can write at an offset', async () => {
const { dir, fs } = setup({
'file.txt': '0123456789',
});
const entry = yield dir.getFileHandle('file.txt');
const sync = yield entry.createSyncAccessHandle();
const res = yield sync.write(Buffer.from('Hello'), { at: 7 });
const entry = await dir.getFileHandle('file.txt');
const sync = await entry.createSyncAccessHandle();
const res = await sync.write(Buffer.from('Hello'), { at: 7 });
expect(res).toBe(5);
expect(fs.readFileSync('/file.txt', 'utf8')).toBe('0123456Hello');
}));
test('throws "InvalidStateError" DOMException if file descriptor is already closed', () => __awaiter(void 0, void 0, void 0, function* () {
});
test('throws "InvalidStateError" DOMException if file descriptor is already closed', async () => {
const { dir, fs } = setup({
'file.txt': '0123456789',
});
const entry = yield dir.getFileHandle('file.txt');
const sync = yield entry.createSyncAccessHandle();
yield sync.write(Buffer.from('a'));
yield sync.close();
const entry = await dir.getFileHandle('file.txt');
const sync = await entry.createSyncAccessHandle();
await sync.write(Buffer.from('a'));
await sync.close();
try {
yield sync.write(Buffer.from('b'));
await sync.write(Buffer.from('b'));
throw new Error('No error was thrown');

@@ -169,12 +160,12 @@ }

}
}));
});
// TODO: Need to find out what is the correct behavior here.
xtest('writing at offset past file size', () => __awaiter(void 0, void 0, void 0, function* () {
xtest('writing at offset past file size', async () => {
const { dir, fs } = setup({
'file.txt': '0123456789',
});
const entry = yield dir.getFileHandle('file.txt');
const sync = yield entry.createSyncAccessHandle();
const entry = await dir.getFileHandle('file.txt');
const sync = await entry.createSyncAccessHandle();
try {
yield sync.write(Buffer.from('a'), { at: 100 });
await sync.write(Buffer.from('a'), { at: 100 });
// ?

@@ -185,4 +176,5 @@ }

}
}));
});
});
});
//# sourceMappingURL=NodeFileSystemSyncAccessHandle.test.js.map
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -16,35 +7,35 @@ const __1 = require("../..");

describe('createSwapFile()', () => {
test('can create a swap file', () => __awaiter(void 0, void 0, void 0, function* () {
const fs = (0, __1.memfs)({
test('can create a swap file', async () => {
const { fs, vol } = (0, __1.memfs)({
'/file.txt': 'Hello, world!',
}, '/');
const [handle, path] = yield (0, NodeFileSystemWritableFileStream_1.createSwapFile)(fs, '/file.txt', false);
const [handle, path] = await (0, NodeFileSystemWritableFileStream_1.createSwapFile)(fs, '/file.txt', false);
expect(handle).toBeInstanceOf(FileHandle_1.FileHandle);
expect(path).toBe('/file.txt.crswap');
expect(fs.__vol.toJSON()).toStrictEqual({
expect(vol.toJSON()).toStrictEqual({
'/file.txt': 'Hello, world!',
'/file.txt.crswap': '',
});
}));
test('can create a swap file at subfolder', () => __awaiter(void 0, void 0, void 0, function* () {
const fs = (0, __1.memfs)({
});
test('can create a swap file at subfolder', async () => {
const { fs, vol } = (0, __1.memfs)({
'/foo/file.txt': 'Hello, world!',
}, '/');
const [handle, path] = yield (0, NodeFileSystemWritableFileStream_1.createSwapFile)(fs, '/foo/file.txt', false);
const [handle, path] = await (0, NodeFileSystemWritableFileStream_1.createSwapFile)(fs, '/foo/file.txt', false);
expect(handle).toBeInstanceOf(FileHandle_1.FileHandle);
expect(path).toBe('/foo/file.txt.crswap');
expect(fs.__vol.toJSON()).toStrictEqual({
expect(vol.toJSON()).toStrictEqual({
'/foo/file.txt': 'Hello, world!',
'/foo/file.txt.crswap': '',
});
}));
test('can create a swap file when the default swap file name is in use', () => __awaiter(void 0, void 0, void 0, function* () {
const fs = (0, __1.memfs)({
});
test('can create a swap file when the default swap file name is in use', async () => {
const { fs, vol } = (0, __1.memfs)({
'/foo/file.txt': 'Hello, world!',
'/foo/file.txt.crswap': 'lala',
}, '/');
const [handle, path] = yield (0, NodeFileSystemWritableFileStream_1.createSwapFile)(fs, '/foo/file.txt', false);
const [handle, path] = await (0, NodeFileSystemWritableFileStream_1.createSwapFile)(fs, '/foo/file.txt', false);
expect(handle).toBeInstanceOf(FileHandle_1.FileHandle);
expect(path).toBe('/foo/file.txt.1.crswap');
expect(fs.__vol.toJSON()).toStrictEqual({
expect(vol.toJSON()).toStrictEqual({
'/foo/file.txt': 'Hello, world!',

@@ -54,5 +45,5 @@ '/foo/file.txt.crswap': 'lala',

});
}));
test('can create a swap file when the first two names are already taken', () => __awaiter(void 0, void 0, void 0, function* () {
const fs = (0, __1.memfs)({
});
test('can create a swap file when the first two names are already taken', async () => {
const { fs, vol } = (0, __1.memfs)({
'/foo/file.txt': 'Hello, world!',

@@ -62,6 +53,6 @@ '/foo/file.txt.crswap': 'lala',

}, '/');
const [handle, path] = yield (0, NodeFileSystemWritableFileStream_1.createSwapFile)(fs, '/foo/file.txt', false);
const [handle, path] = await (0, NodeFileSystemWritableFileStream_1.createSwapFile)(fs, '/foo/file.txt', false);
expect(handle).toBeInstanceOf(FileHandle_1.FileHandle);
expect(path).toBe('/foo/file.txt.2.crswap');
expect(fs.__vol.toJSON()).toStrictEqual({
expect(vol.toJSON()).toStrictEqual({
'/foo/file.txt': 'Hello, world!',

@@ -72,5 +63,5 @@ '/foo/file.txt.crswap': 'lala',

});
}));
test('can create a swap file when the first three names are already taken', () => __awaiter(void 0, void 0, void 0, function* () {
const fs = (0, __1.memfs)({
});
test('can create a swap file when the first three names are already taken', async () => {
const { fs, vol } = (0, __1.memfs)({
'/foo/file.txt': 'Hello, world!',

@@ -81,6 +72,6 @@ '/foo/file.txt.crswap': 'lala',

}, '/');
const [handle, path] = yield (0, NodeFileSystemWritableFileStream_1.createSwapFile)(fs, '/foo/file.txt', false);
const [handle, path] = await (0, NodeFileSystemWritableFileStream_1.createSwapFile)(fs, '/foo/file.txt', false);
expect(handle).toBeInstanceOf(FileHandle_1.FileHandle);
expect(path).toBe('/foo/file.txt.3.crswap');
expect(fs.__vol.toJSON()).toStrictEqual({
expect(vol.toJSON()).toStrictEqual({
'/foo/file.txt': 'Hello, world!',

@@ -92,5 +83,5 @@ '/foo/file.txt.crswap': 'lala',

});
}));
test('can copy existing data into the swap file', () => __awaiter(void 0, void 0, void 0, function* () {
const fs = (0, __1.memfs)({
});
test('can copy existing data into the swap file', async () => {
const { fs, vol } = (0, __1.memfs)({
'/foo/file.txt': 'Hello, world!',

@@ -101,6 +92,6 @@ '/foo/file.txt.crswap': 'lala',

}, '/');
const [handle, path] = yield (0, NodeFileSystemWritableFileStream_1.createSwapFile)(fs, '/foo/file.txt', true);
const [handle, path] = await (0, NodeFileSystemWritableFileStream_1.createSwapFile)(fs, '/foo/file.txt', true);
expect(handle).toBeInstanceOf(FileHandle_1.FileHandle);
expect(path).toBe('/foo/file.txt.3.crswap');
expect(fs.__vol.toJSON()).toStrictEqual({
expect(vol.toJSON()).toStrictEqual({
'/foo/file.txt': 'Hello, world!',

@@ -112,3 +103,4 @@ '/foo/file.txt.crswap': 'lala',

});
}));
});
});
//# sourceMappingURL=NodeFileSystemWritableFileStream.test.js.map
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -16,4 +7,4 @@ const __1 = require("..");

(0, util_1.onlyOnNode20)('scenarios', () => {
test('can init FSA from an arbitrary FS folder and execute operations', () => __awaiter(void 0, void 0, void 0, function* () {
const fs = (0, __2.memfs)({
test('can init FSA from an arbitrary FS folder and execute operations', async () => {
const { fs, vol } = (0, __2.memfs)({
'/tmp': null,

@@ -25,16 +16,16 @@ '/etc': null,

const dir = (0, __1.nodeToFsa)(fs, '/Users/kasper/Documents', { mode: 'readwrite' });
const shoppingListFile = yield dir.getFileHandle('shopping-list.txt');
const shoppingList = yield shoppingListFile.getFile();
expect(yield shoppingList.text()).toBe('Milk, Eggs, Bread');
const backupsDir = yield dir.getDirectoryHandle('backups', { create: true });
const backupFile = yield backupsDir.getFileHandle('shopping-list.txt', { create: true });
const writable = yield backupFile.createWritable();
yield writable.write(yield shoppingList.arrayBuffer());
yield writable.close();
const logsFileHandle = yield dir.getFileHandle('logs.csv', { create: true });
const logsWritable = yield logsFileHandle.createWritable();
yield logsWritable.write('timestamp,level,message\n');
yield logsWritable.write({ type: 'write', data: '2021-01-01T00:00:00Z,INFO,Hello World\n' });
yield logsWritable.close();
expect(fs.__vol.toJSON()).toStrictEqual({
const shoppingListFile = await dir.getFileHandle('shopping-list.txt');
const shoppingList = await shoppingListFile.getFile();
expect(await shoppingList.text()).toBe('Milk, Eggs, Bread');
const backupsDir = await dir.getDirectoryHandle('backups', { create: true });
const backupFile = await backupsDir.getFileHandle('shopping-list.txt', { create: true });
const writable = await backupFile.createWritable();
await writable.write(await shoppingList.arrayBuffer());
await writable.close();
const logsFileHandle = await dir.getFileHandle('logs.csv', { create: true });
const logsWritable = await logsFileHandle.createWritable();
await logsWritable.write('timestamp,level,message\n');
await logsWritable.write({ type: 'write', data: '2021-01-01T00:00:00Z,INFO,Hello World\n' });
await logsWritable.close();
expect(vol.toJSON()).toStrictEqual({
'/tmp': null,

@@ -47,3 +38,4 @@ '/etc': null,

});
}));
});
});
//# sourceMappingURL=scenarios.test.js.map

@@ -11,2 +11,6 @@ "use strict";

});
test('ignores slash, if it is the last char', () => {
expect((0, util_1.basename)('scary.exe/', '/')).toBe('scary.exe');
expect((0, util_1.basename)('/ab/c/scary.exe/', '/')).toBe('scary.exe');
});
test('returns last step in path', () => {

@@ -27,1 +31,2 @@ expect((0, util_1.basename)('/gg/wp/hf/gl.txt', '/')).toBe('gl.txt');

});
//# sourceMappingURL=util.test.js.map
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.nodeToFsa = void 0;
const tslib_1 = require("tslib");
const NodeFileSystemDirectoryHandle_1 = require("./NodeFileSystemDirectoryHandle");
__exportStar(require("./types"), exports);
__exportStar(require("./NodeFileSystemHandle"), exports);
__exportStar(require("./NodeFileSystemDirectoryHandle"), exports);
__exportStar(require("./NodeFileSystemFileHandle"), exports);
tslib_1.__exportStar(require("./types"), exports);
tslib_1.__exportStar(require("./NodeFileSystemHandle"), exports);
tslib_1.__exportStar(require("./NodeFileSystemDirectoryHandle"), exports);
tslib_1.__exportStar(require("./NodeFileSystemFileHandle"), exports);
const nodeToFsa = (fs, dirPath, ctx) => {

@@ -27,1 +14,2 @@ return new NodeFileSystemDirectoryHandle_1.NodeFileSystemDirectoryHandle(fs, dirPath, ctx);

exports.nodeToFsa = nodeToFsa;
//# sourceMappingURL=index.js.map

@@ -9,5 +9,6 @@ import { NodeFileSystemHandle } from './NodeFileSystemHandle';

protected readonly fs: NodeFsaFs;
protected readonly ctx: Partial<NodeFsaContext>;
/** Directory path with trailing slash. */
readonly __path: string;
protected readonly ctx: Partial<NodeFsaContext>;
constructor(fs: NodeFsaFs, __path: string, ctx?: Partial<NodeFsaContext>);
constructor(fs: NodeFsaFs, path: string, ctx?: Partial<NodeFsaContext>);
/**

@@ -14,0 +15,0 @@ * Returns a new array iterator containing the keys for each item in

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var g = generator.apply(thisArg, _arguments || []), i, q = [];
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
function fulfill(value) { resume("next", value); }
function reject(value) { resume("throw", value); }
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
};
var __asyncValues = (this && this.__asyncValues) || function (o) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var m = o[Symbol.asyncIterator], i;
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.NodeFileSystemDirectoryHandle = void 0;
const tslib_1 = require("tslib");
const NodeFileSystemHandle_1 = require("./NodeFileSystemHandle");

@@ -39,7 +12,7 @@ const util_1 = require("./util");

class NodeFileSystemDirectoryHandle extends NodeFileSystemHandle_1.NodeFileSystemHandle {
constructor(fs, __path, ctx = {}) {
super('directory', (0, util_1.basename)(__path, ctx.separator || '/'));
constructor(fs, path, ctx = {}) {
super('directory', (0, util_1.basename)(path, ctx.separator || '/'));
this.fs = fs;
this.__path = __path;
this.ctx = (0, util_1.ctx)(ctx);
this.__path = path[path.length - 1] === this.ctx.separator ? path : path + this.ctx.separator;
}

@@ -53,6 +26,6 @@ /**

keys() {
return __asyncGenerator(this, arguments, function* keys_1() {
const list = yield __await(this.fs.promises.readdir(this.__path));
return tslib_1.__asyncGenerator(this, arguments, function* keys_1() {
const list = yield tslib_1.__await(this.fs.promises.readdir(this.__path));
for (const name of list)
yield yield __await('' + name);
yield yield tslib_1.__await('' + name);
});

@@ -64,5 +37,5 @@ }

entries() {
return __asyncGenerator(this, arguments, function* entries_1() {
return tslib_1.__asyncGenerator(this, arguments, function* entries_1() {
const { __path: path, fs, ctx } = this;
const list = yield __await(fs.promises.readdir(path, { withFileTypes: true }));
const list = yield tslib_1.__await(fs.promises.readdir(path, { withFileTypes: true }));
for (const d of list) {

@@ -73,5 +46,5 @@ const dirent = d;

if (dirent.isDirectory())
yield yield __await([name, new NodeFileSystemDirectoryHandle(fs, newPath, ctx)]);
yield yield tslib_1.__await([name, new NodeFileSystemDirectoryHandle(fs, newPath, ctx)]);
else if (dirent.isFile())
yield yield __await([name, new NodeFileSystemFileHandle_1.NodeFileSystemFileHandle(fs, name, ctx)]);
yield yield tslib_1.__await([name, new NodeFileSystemFileHandle_1.NodeFileSystemFileHandle(fs, name, ctx)]);
}

@@ -87,15 +60,10 @@ });

values() {
return __asyncGenerator(this, arguments, function* values_1() {
return tslib_1.__asyncGenerator(this, arguments, function* values_1() {
var _a, e_1, _b, _c;
try {
for (var _d = true, _e = __asyncValues(this.entries()), _f; _f = yield __await(_e.next()), _a = _f.done, !_a;) {
for (var _d = true, _e = tslib_1.__asyncValues(this.entries()), _f; _f = yield tslib_1.__await(_e.next()), _a = _f.done, !_a; _d = true) {
_c = _f.value;
_d = false;
try {
const [, value] = _c;
yield yield __await(value);
}
finally {
_d = true;
}
const [, value] = _c;
yield yield tslib_1.__await(value);
}

@@ -106,3 +74,3 @@ }

try {
if (!_d && !_a && (_b = _e.return)) yield __await(_b.call(_e));
if (!_d && !_a && (_b = _e.return)) yield tslib_1.__await(_b.call(_e));
}

@@ -123,33 +91,31 @@ finally { if (e_1) throw e_1.error; }

*/
getDirectoryHandle(name, options) {
return __awaiter(this, void 0, void 0, function* () {
(0, util_1.assertName)(name, 'getDirectoryHandle', 'FileSystemDirectoryHandle');
const filename = this.__path + this.ctx.separator + name;
try {
const stats = yield this.fs.promises.stat(filename);
if (!stats.isDirectory())
throw (0, util_1.newTypeMismatchError)();
return new NodeFileSystemDirectoryHandle(this.fs, filename, this.ctx);
}
catch (error) {
if (error instanceof DOMException)
throw error;
if (error && typeof error === 'object') {
switch (error.code) {
case 'ENOENT': {
if (options === null || options === void 0 ? void 0 : options.create) {
(0, util_1.assertCanWrite)(this.ctx.mode);
yield this.fs.promises.mkdir(filename);
return new NodeFileSystemDirectoryHandle(this.fs, filename, this.ctx);
}
throw (0, util_1.newNotFoundError)();
async getDirectoryHandle(name, options) {
(0, util_1.assertName)(name, 'getDirectoryHandle', 'FileSystemDirectoryHandle');
const filename = this.__path + name;
try {
const stats = await this.fs.promises.stat(filename);
if (!stats.isDirectory())
throw (0, util_1.newTypeMismatchError)();
return new NodeFileSystemDirectoryHandle(this.fs, filename, this.ctx);
}
catch (error) {
if (error instanceof DOMException)
throw error;
if (error && typeof error === 'object') {
switch (error.code) {
case 'ENOENT': {
if (options === null || options === void 0 ? void 0 : options.create) {
(0, util_1.assertCanWrite)(this.ctx.mode);
await this.fs.promises.mkdir(filename);
return new NodeFileSystemDirectoryHandle(this.fs, filename, this.ctx);
}
case 'EPERM':
case 'EACCES':
throw (0, util_1.newNotAllowedError)();
throw (0, util_1.newNotFoundError)();
}
case 'EPERM':
case 'EACCES':
throw (0, util_1.newNotAllowedError)();
}
throw error;
}
});
throw error;
}
}

@@ -165,33 +131,31 @@ /**

*/
getFileHandle(name, options) {
return __awaiter(this, void 0, void 0, function* () {
(0, util_1.assertName)(name, 'getFileHandle', 'FileSystemDirectoryHandle');
const filename = this.__path + this.ctx.separator + name;
try {
const stats = yield this.fs.promises.stat(filename);
if (!stats.isFile())
throw (0, util_1.newTypeMismatchError)();
return new NodeFileSystemFileHandle_1.NodeFileSystemFileHandle(this.fs, filename, this.ctx);
}
catch (error) {
if (error instanceof DOMException)
throw error;
if (error && typeof error === 'object') {
switch (error.code) {
case 'ENOENT': {
if (options === null || options === void 0 ? void 0 : options.create) {
(0, util_1.assertCanWrite)(this.ctx.mode);
yield this.fs.promises.writeFile(filename, '');
return new NodeFileSystemFileHandle_1.NodeFileSystemFileHandle(this.fs, filename, this.ctx);
}
throw (0, util_1.newNotFoundError)();
async getFileHandle(name, options) {
(0, util_1.assertName)(name, 'getFileHandle', 'FileSystemDirectoryHandle');
const filename = this.__path + name;
try {
const stats = await this.fs.promises.stat(filename);
if (!stats.isFile())
throw (0, util_1.newTypeMismatchError)();
return new NodeFileSystemFileHandle_1.NodeFileSystemFileHandle(this.fs, filename, this.ctx);
}
catch (error) {
if (error instanceof DOMException)
throw error;
if (error && typeof error === 'object') {
switch (error.code) {
case 'ENOENT': {
if (options === null || options === void 0 ? void 0 : options.create) {
(0, util_1.assertCanWrite)(this.ctx.mode);
await this.fs.promises.writeFile(filename, '');
return new NodeFileSystemFileHandle_1.NodeFileSystemFileHandle(this.fs, filename, this.ctx);
}
case 'EPERM':
case 'EACCES':
throw (0, util_1.newNotAllowedError)();
throw (0, util_1.newNotFoundError)();
}
case 'EPERM':
case 'EACCES':
throw (0, util_1.newNotAllowedError)();
}
throw error;
}
});
throw error;
}
}

@@ -207,37 +171,35 @@ /**

*/
removeEntry(name, { recursive = false } = {}) {
return __awaiter(this, void 0, void 0, function* () {
(0, util_1.assertCanWrite)(this.ctx.mode);
(0, util_1.assertName)(name, 'removeEntry', 'FileSystemDirectoryHandle');
const filename = this.__path + this.ctx.separator + name;
const promises = this.fs.promises;
try {
const stats = yield promises.stat(filename);
if (stats.isFile()) {
yield promises.unlink(filename);
}
else if (stats.isDirectory()) {
yield promises.rmdir(filename, { recursive });
}
else
throw (0, util_1.newTypeMismatchError)();
async removeEntry(name, { recursive = false } = {}) {
(0, util_1.assertCanWrite)(this.ctx.mode);
(0, util_1.assertName)(name, 'removeEntry', 'FileSystemDirectoryHandle');
const filename = this.__path + name;
const promises = this.fs.promises;
try {
const stats = await promises.stat(filename);
if (stats.isFile()) {
await promises.unlink(filename);
}
catch (error) {
if (error instanceof DOMException)
throw error;
if (error && typeof error === 'object') {
switch (error.code) {
case 'ENOENT': {
throw (0, util_1.newNotFoundError)();
}
case 'EPERM':
case 'EACCES':
throw (0, util_1.newNotAllowedError)();
case 'ENOTEMPTY':
throw new DOMException('The object can not be modified in this way.', 'InvalidModificationError');
else if (stats.isDirectory()) {
await promises.rmdir(filename, { recursive });
}
else
throw (0, util_1.newTypeMismatchError)();
}
catch (error) {
if (error instanceof DOMException)
throw error;
if (error && typeof error === 'object') {
switch (error.code) {
case 'ENOENT': {
throw (0, util_1.newNotFoundError)();
}
case 'EPERM':
case 'EACCES':
throw (0, util_1.newNotAllowedError)();
case 'ENOTEMPTY':
throw new DOMException('The object can not be modified in this way.', 'InvalidModificationError');
}
throw error;
}
});
throw error;
}
}

@@ -253,22 +215,21 @@ /**

*/
resolve(possibleDescendant) {
return __awaiter(this, void 0, void 0, function* () {
if (possibleDescendant instanceof NodeFileSystemDirectoryHandle ||
possibleDescendant instanceof NodeFileSystemFileHandle_1.NodeFileSystemFileHandle) {
const path = this.__path;
const childPath = possibleDescendant.__path;
if (!childPath.startsWith(path))
return null;
let relative = childPath.slice(path.length);
if (relative === '')
return [];
const separator = this.ctx.separator;
if (relative[0] === separator)
relative = relative.slice(1);
return relative.split(separator);
}
return null;
});
async resolve(possibleDescendant) {
if (possibleDescendant instanceof NodeFileSystemDirectoryHandle ||
possibleDescendant instanceof NodeFileSystemFileHandle_1.NodeFileSystemFileHandle) {
const path = this.__path;
const childPath = possibleDescendant.__path;
if (!childPath.startsWith(path))
return null;
let relative = childPath.slice(path.length);
if (relative === '')
return [];
const separator = this.ctx.separator;
if (relative[0] === separator)
relative = relative.slice(1);
return relative.split(separator);
}
return null;
}
}
exports.NodeFileSystemDirectoryHandle = NodeFileSystemDirectoryHandle;
//# sourceMappingURL=NodeFileSystemDirectoryHandle.js.map
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -31,25 +22,24 @@ exports.NodeFileSystemFileHandle = void 0;

*/
getFile() {
return __awaiter(this, void 0, void 0, function* () {
try {
const path = this.__path;
const promises = this.fs.promises;
const stats = yield promises.stat(path);
const data = yield promises.readFile(path);
const file = new File([data], this.name, { lastModified: stats.mtime.getTime() });
return file;
}
catch (error) {
if (error instanceof DOMException)
throw error;
if (error && typeof error === 'object') {
switch (error.code) {
case 'EPERM':
case 'EACCES':
throw (0, util_1.newNotAllowedError)();
}
async getFile() {
try {
const path = this.__path;
const promises = this.fs.promises;
const stats = await promises.stat(path);
// TODO: Once implemented, use promises.readAsBlob() instead of promises.readFile().
const data = await promises.readFile(path);
const file = new File([data], this.name, { lastModified: stats.mtime.getTime() });
return file;
}
catch (error) {
if (error instanceof DOMException)
throw error;
if (error && typeof error === 'object') {
switch (error.code) {
case 'EPERM':
case 'EACCES':
throw (0, util_1.newNotAllowedError)();
}
throw error;
}
});
throw error;
}
}

@@ -62,3 +52,3 @@ /**

return undefined;
return () => __awaiter(this, void 0, void 0, function* () { return new NodeFileSystemSyncAccessHandle_1.NodeFileSystemSyncAccessHandle(this.fs, this.__path, this.ctx); });
return async () => new NodeFileSystemSyncAccessHandle_1.NodeFileSystemSyncAccessHandle(this.fs, this.__path, this.ctx);
}

@@ -68,9 +58,8 @@ /**

*/
createWritable({ keepExistingData = false } = { keepExistingData: false }) {
return __awaiter(this, void 0, void 0, function* () {
(0, util_1.assertCanWrite)(this.ctx.mode);
return new NodeFileSystemWritableFileStream_1.NodeFileSystemWritableFileStream(this.fs, this.__path, keepExistingData);
});
async createWritable({ keepExistingData = false } = { keepExistingData: false }) {
(0, util_1.assertCanWrite)(this.ctx.mode);
return new NodeFileSystemWritableFileStream_1.NodeFileSystemWritableFileStream(this.fs, this.__path, keepExistingData);
}
}
exports.NodeFileSystemFileHandle = NodeFileSystemFileHandle;
//# sourceMappingURL=NodeFileSystemFileHandle.js.map
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -41,6 +32,4 @@ exports.NodeFileSystemHandle = void 0;

*/
remove({ recursive } = { recursive: false }) {
return __awaiter(this, void 0, void 0, function* () {
throw new Error('Not implemented');
});
async remove({ recursive } = { recursive: false }) {
throw new Error('Not implemented');
}

@@ -55,1 +44,2 @@ /**

exports.NodeFileSystemHandle = NodeFileSystemHandle;
//# sourceMappingURL=NodeFileSystemHandle.js.map
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -27,7 +18,5 @@ exports.NodeFileSystemSyncAccessHandle = void 0;

*/
close() {
return __awaiter(this, void 0, void 0, function* () {
(0, util_1.assertCanWrite)(this.ctx.mode);
this.fs.closeSync(this.fd);
});
async close() {
(0, util_1.assertCanWrite)(this.ctx.mode);
this.fs.closeSync(this.fd);
}

@@ -37,7 +26,5 @@ /**

*/
flush() {
return __awaiter(this, void 0, void 0, function* () {
(0, util_1.assertCanWrite)(this.ctx.mode);
this.fs.fsyncSync(this.fd);
});
async flush() {
(0, util_1.assertCanWrite)(this.ctx.mode);
this.fs.fsyncSync(this.fd);
}

@@ -47,6 +34,4 @@ /**

*/
getSize() {
return __awaiter(this, void 0, void 0, function* () {
return this.fs.statSync(this.path).size;
});
async getSize() {
return this.fs.statSync(this.path).size;
}

@@ -56,23 +41,21 @@ /**

*/
read(buffer, options = {}) {
async read(buffer, options = {}) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
const buf = buffer instanceof ArrayBuffer ? Buffer.from(buffer) : buffer;
try {
const size = this.fs.readSync(this.fd, buf, 0, buffer.byteLength, (_a = options.at) !== null && _a !== void 0 ? _a : 0);
return size;
}
catch (error) {
if (error instanceof DOMException)
throw error;
if (error && typeof error === 'object') {
switch (error.code) {
case 'EBADF': {
throw new DOMException('File handle already closed.', 'InvalidStateError');
}
const buf = buffer instanceof ArrayBuffer ? Buffer.from(buffer) : buffer;
try {
const size = this.fs.readSync(this.fd, buf, 0, buffer.byteLength, (_a = options.at) !== null && _a !== void 0 ? _a : 0);
return size;
}
catch (error) {
if (error instanceof DOMException)
throw error;
if (error && typeof error === 'object') {
switch (error.code) {
case 'EBADF': {
throw new DOMException('File handle already closed.', 'InvalidStateError');
}
}
throw error;
}
});
throw error;
}
}

@@ -83,7 +66,5 @@ /**

*/
truncate(newSize) {
return __awaiter(this, void 0, void 0, function* () {
(0, util_1.assertCanWrite)(this.ctx.mode);
this.fs.truncateSync(this.fd, newSize);
});
async truncate(newSize) {
(0, util_1.assertCanWrite)(this.ctx.mode);
this.fs.truncateSync(this.fd, newSize);
}

@@ -98,25 +79,24 @@ /**

*/
write(buffer, options = {}) {
async write(buffer, options = {}) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
(0, util_1.assertCanWrite)(this.ctx.mode);
const buf = buffer instanceof ArrayBuffer ? Buffer.from(buffer) : buffer;
try {
return this.fs.writeSync(this.fd, buf, 0, buffer.byteLength, (_a = options.at) !== null && _a !== void 0 ? _a : 0);
}
catch (error) {
if (error instanceof DOMException)
throw error;
if (error && typeof error === 'object') {
switch (error.code) {
case 'EBADF': {
throw new DOMException('File handle already closed.', 'InvalidStateError');
}
(0, util_1.assertCanWrite)(this.ctx.mode);
const buf = buffer instanceof ArrayBuffer ? Buffer.from(buffer) : buffer;
try {
return this.fs.writeSync(this.fd, buf, 0, buffer.byteLength, (_a = options.at) !== null && _a !== void 0 ? _a : 0);
}
catch (error) {
if (error instanceof DOMException)
throw error;
if (error && typeof error === 'object') {
switch (error.code) {
case 'EBADF': {
throw new DOMException('File handle already closed.', 'InvalidStateError');
}
}
throw error;
}
});
throw error;
}
}
}
exports.NodeFileSystemSyncAccessHandle = NodeFileSystemSyncAccessHandle;
//# sourceMappingURL=NodeFileSystemSyncAccessHandle.js.map
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -22,7 +13,7 @@ exports.NodeFileSystemWritableFileStream = exports.createSwapFile = void 0;

*/
const createSwapFile = (fs, path, keepExistingData) => __awaiter(void 0, void 0, void 0, function* () {
const createSwapFile = async (fs, path, keepExistingData) => {
let handle;
let swapPath = path + '.crswap';
try {
handle = yield fs.promises.open(swapPath, 'ax');
handle = await fs.promises.open(swapPath, 'ax');
}

@@ -37,3 +28,3 @@ catch (error) {

swapPath = `${path}.${i}.crswap`;
handle = yield fs.promises.open(swapPath, 'ax');
handle = await fs.promises.open(swapPath, 'ax');
break;

@@ -50,5 +41,5 @@ }

if (keepExistingData)
yield fs.promises.copyFile(path, swapPath, fs.constants.COPYFILE_FICLONE);
await fs.promises.copyFile(path, swapPath, fs.constants.COPYFILE_FICLONE);
return [handle, swapPath];
});
};
exports.createSwapFile = createSwapFile;

@@ -66,41 +57,33 @@ /**

super({
start() {
return __awaiter(this, void 0, void 0, function* () {
const promise = (0, exports.createSwapFile)(fs, path, keepExistingData);
swap.ready = promise.then(() => undefined);
const [handle, swapPath] = yield promise;
swap.handle = handle;
swap.path = swapPath;
});
async start() {
const promise = (0, exports.createSwapFile)(fs, path, keepExistingData);
swap.ready = promise.then(() => undefined);
const [handle, swapPath] = await promise;
swap.handle = handle;
swap.path = swapPath;
},
write(chunk) {
return __awaiter(this, void 0, void 0, function* () {
yield swap.ready;
const handle = swap.handle;
if (!handle)
throw new Error('Invalid state');
const buffer = Buffer.from(typeof chunk === 'string' ? chunk : chunk instanceof Blob ? yield chunk.arrayBuffer() : chunk);
const { bytesWritten } = yield handle.write(buffer, 0, buffer.length, swap.offset);
swap.offset += bytesWritten;
});
async write(chunk) {
await swap.ready;
const handle = swap.handle;
if (!handle)
throw new Error('Invalid state');
const buffer = Buffer.from(typeof chunk === 'string' ? chunk : chunk instanceof Blob ? await chunk.arrayBuffer() : chunk);
const { bytesWritten } = await handle.write(buffer, 0, buffer.length, swap.offset);
swap.offset += bytesWritten;
},
close() {
return __awaiter(this, void 0, void 0, function* () {
yield swap.ready;
const handle = swap.handle;
if (!handle)
return;
yield handle.close();
yield fs.promises.rename(swap.path, path);
});
async close() {
await swap.ready;
const handle = swap.handle;
if (!handle)
return;
await handle.close();
await fs.promises.rename(swap.path, path);
},
abort() {
return __awaiter(this, void 0, void 0, function* () {
yield swap.ready;
const handle = swap.handle;
if (!handle)
return;
yield handle.close();
yield fs.promises.unlink(swap.path);
});
async abort() {
await swap.ready;
const handle = swap.handle;
if (!handle)
return;
await handle.close();
await fs.promises.unlink(swap.path);
},

@@ -117,6 +100,4 @@ });

*/
seek(position) {
return __awaiter(this, void 0, void 0, function* () {
this.swap.offset = position;
});
async seek(position) {
this.swap.offset = position;
}

@@ -127,65 +108,59 @@ /**

*/
truncate(size) {
return __awaiter(this, void 0, void 0, function* () {
yield this.swap.ready;
const handle = this.swap.handle;
if (!handle)
throw new Error('Invalid state');
yield handle.truncate(size);
if (this.swap.offset > size)
this.swap.offset = size;
});
async truncate(size) {
await this.swap.ready;
const handle = this.swap.handle;
if (!handle)
throw new Error('Invalid state');
await handle.truncate(size);
if (this.swap.offset > size)
this.swap.offset = size;
}
writeBase(chunk) {
return __awaiter(this, void 0, void 0, function* () {
const writer = this.getWriter();
try {
yield writer.write(chunk);
async writeBase(chunk) {
const writer = this.getWriter();
try {
await writer.write(chunk);
}
finally {
writer.releaseLock();
}
}
async write(params) {
if (!params)
throw new TypeError('Missing required argument: params');
switch (typeof params) {
case 'string': {
return this.writeBase(params);
}
finally {
writer.releaseLock();
}
});
}
write(params) {
return __awaiter(this, void 0, void 0, function* () {
if (!params)
throw new TypeError('Missing required argument: params');
switch (typeof params) {
case 'string': {
return this.writeBase(params);
}
case 'object': {
const constructor = params.constructor;
switch (constructor) {
case ArrayBuffer:
case Blob:
case DataView:
case 'object': {
const constructor = params.constructor;
switch (constructor) {
case ArrayBuffer:
case Blob:
case DataView:
return this.writeBase(params);
default: {
if (ArrayBuffer.isView(params)) {
return this.writeBase(params);
default: {
if (ArrayBuffer.isView(params)) {
return this.writeBase(params);
}
else {
const options = params;
switch (options.type) {
case 'write': {
if (typeof options.position === 'number')
yield this.seek(options.position);
return this.writeBase(params.data);
}
case 'truncate': {
if (typeof params.size !== 'number')
throw new TypeError('Missing required argument: size');
if (this.swap.offset > params.size)
this.swap.offset = params.size;
return this.truncate(params.size);
}
case 'seek':
if (typeof params.position !== 'number')
throw new TypeError('Missing required argument: position');
return this.seek(params.position);
default:
throw new TypeError('Invalid argument: params');
}
else {
const options = params;
switch (options.type) {
case 'write': {
if (typeof options.position === 'number')
await this.seek(options.position);
return this.writeBase(params.data);
}
case 'truncate': {
if (typeof params.size !== 'number')
throw new TypeError('Missing required argument: size');
if (this.swap.offset > params.size)
this.swap.offset = params.size;
return this.truncate(params.size);
}
case 'seek':
if (typeof params.position !== 'number')
throw new TypeError('Missing required argument: position');
return this.seek(params.position);
default:
throw new TypeError('Invalid argument: params');
}

@@ -195,8 +170,9 @@ }

}
default:
throw new TypeError('Invalid argument: params');
}
});
default:
throw new TypeError('Invalid argument: params');
}
}
}
exports.NodeFileSystemWritableFileStream = NodeFileSystemWritableFileStream;
//# sourceMappingURL=NodeFileSystemWritableFileStream.js.map

@@ -14,1 +14,2 @@ "use strict";

exports.NodePermissionStatus = NodePermissionStatus;
//# sourceMappingURL=NodePermissionStatus.js.map

@@ -1,6 +0,9 @@

import type { IFs } from '..';
import type { FsPromisesApi, FsSynchronousApi } from '../node/types';
import type { FsCommonObjects } from '../node/types/FsCommonObjects';
/**
* Required Node.js `fs` module functions for File System Access API.
*/
export type NodeFsaFs = Pick<IFs, 'promises' | 'constants' | 'openSync' | 'fsyncSync' | 'statSync' | 'closeSync' | 'readSync' | 'truncateSync' | 'writeSync'>;
export type NodeFsaFs = Pick<FsCommonObjects, 'constants'> & {
promises: FsPromisesApi;
} & Pick<FsSynchronousApi, 'openSync' | 'fsyncSync' | 'statSync' | 'closeSync' | 'readSync' | 'truncateSync' | 'writeSync'>;
export interface NodeFsaContext {

@@ -7,0 +10,0 @@ separator: '/' | '\\';

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=types.js.map

@@ -12,2 +12,4 @@ "use strict";

const basename = (path, separator) => {
if (path[path.length - 1] === separator)
path = path.slice(0, -1);
const lastSlashIndex = path.lastIndexOf(separator);

@@ -35,1 +37,2 @@ return lastSlashIndex === -1 ? path : path.slice(lastSlashIndex + 1);

exports.newNotAllowedError = newNotAllowedError;
//# sourceMappingURL=util.js.map

@@ -431,1 +431,2 @@ "use strict";

exports.File = File;
//# sourceMappingURL=node.js.map

@@ -56,2 +56,3 @@ "use strict";

FLAGS[FLAGS["xa+"] = FLAGS['ax+']] = "xa+";
})(FLAGS = exports.FLAGS || (exports.FLAGS = {}));
})(FLAGS || (exports.FLAGS = FLAGS = {}));
//# sourceMappingURL=constants.js.map

@@ -51,1 +51,2 @@ "use strict";

exports.FileHandle = FileHandle;
//# sourceMappingURL=FileHandle.js.map

@@ -95,1 +95,2 @@ "use strict";

exports.getWriteFileOptions = optsGenerator(exports.writeFileDefaults);
//# sourceMappingURL=options.js.map

@@ -9,10 +9,10 @@ import type { constants } from '../../constants';

constants: typeof constants;
Stats: new (...args: unknown[]) => misc.IStats;
StatFs: unknown;
Dir: unknown;
Dir: new (...args: unknown[]) => misc.IDir;
Dirent: new (...args: unknown[]) => misc.IDirent;
StatsWatcher: new (...args: unknown[]) => misc.IStatWatcher;
FSWatcher: new (...args: unknown[]) => misc.IFSWatcher;
ReadStream: new (...args: unknown[]) => misc.IReadStream;
StatFs: new (...args: unknown[]) => misc.IStatFs;
Stats: new (...args: unknown[]) => misc.IStats;
StatsWatcher: new (...args: unknown[]) => misc.IStatWatcher;
WriteStream: new (...args: unknown[]) => misc.IWriteStream;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=FsCommonObjects.js.map

@@ -6,18 +6,31 @@ /// <reference types="node" />

export interface FsSynchronousApi {
openSync(path: misc.PathLike, flags: misc.TFlags, mode?: misc.TMode): number;
accessSync(path: misc.PathLike, mode?: number): void;
appendFileSync(id: misc.TFileId, data: misc.TData, options?: opts.IAppendFileOptions | string): void;
chmodSync(path: misc.PathLike, mode: misc.TMode): void;
chownSync(path: misc.PathLike, uid: number, gid: number): void;
closeSync(fd: number): void;
readSync(fd: number, buffer: Buffer | ArrayBufferView | DataView, offset: number, length: number, position: number): number;
readFileSync(file: misc.TFileId, options?: opts.IReadFileOptions | string): misc.TDataOut;
writeSync(fd: number, buffer: Buffer | ArrayBufferView | DataView, offset?: number, length?: number, position?: number): number;
writeSync(fd: number, str: string, position?: number, encoding?: BufferEncoding): number;
writeFileSync(id: misc.TFileId, data: misc.TData, options?: opts.IWriteFileOptions): void;
copyFileSync(src: misc.PathLike, dest: misc.PathLike, flags?: misc.TFlagsCopy): void;
cpSync(src: string | URL, dest: string | URL, options?: opts.ICpOptions): void;
existsSync(path: misc.PathLike): boolean;
fchmodSync(fd: number, mode: misc.TMode): void;
fchownSync(fd: number, uid: number, gid: number): void;
fdatasyncSync(fd: number): void;
fstatSync(fd: number, options: {
bigint: false;
}): misc.IStats<number>;
fstatSync(fd: number, options: {
bigint: true;
}): misc.IStats<bigint>;
fstatSync(fd: number): misc.IStats<number>;
fsyncSync(fd: number): void;
ftruncateSync(fd: number, len?: number): void;
futimesSync(fd: number, atime: misc.TTime, mtime: misc.TTime): void;
lchmodSync(path: misc.PathLike, mode: misc.TMode): void;
lchownSync(path: misc.PathLike, uid: number, gid: number): void;
lutimesSync(path: misc.PathLike, atime: number | string | Date, time: number | string | Date): void;
linkSync(existingPath: misc.PathLike, newPath: misc.PathLike): void;
unlinkSync(path: misc.PathLike): void;
symlinkSync(target: misc.PathLike, path: misc.PathLike, type?: misc.symlink.Type): void;
realpathSync(path: misc.PathLike, options?: opts.IRealpathOptions | string): misc.TDataOut;
lstatSync(path: misc.PathLike): misc.IStats<number>;
lstatSync(path: misc.PathLike, options: {
throwIfNoEntry?: true | undefined;
}): misc.IStats<number>;
bigint: false;
throwIfNoEntry: false;
}): misc.IStats<number> | undefined;
lstatSync(path: misc.PathLike, options: {

@@ -29,2 +42,6 @@ bigint: false;

bigint: true;
throwIfNoEntry: false;
}): misc.IStats<bigint> | undefined;
lstatSync(path: misc.PathLike, options: {
bigint: true;
throwIfNoEntry?: true | undefined;

@@ -36,14 +53,26 @@ }): misc.IStats<bigint>;

lstatSync(path: misc.PathLike, options: {
bigint: false;
throwIfNoEntry: false;
}): misc.IStats<number> | undefined;
lstatSync(path: misc.PathLike, options: {
bigint: true;
throwIfNoEntry: false;
}): misc.IStats<bigint> | undefined;
statSync(path: misc.PathLike): misc.IStats<number>;
statSync(path: misc.PathLike, options: {
throwIfNoEntry?: true;
throwIfNoEntry?: true | undefined;
}): misc.IStats<number>;
lstatSync(path: misc.PathLike): misc.IStats<number>;
mkdirSync(path: misc.PathLike, options: opts.IMkdirOptions & {
recursive: true;
}): string | undefined;
mkdirSync(path: misc.PathLike, options?: misc.TMode | (opts.IMkdirOptions & {
recursive?: false;
})): void;
mkdirSync(path: misc.PathLike, options?: misc.TMode | opts.IMkdirOptions): string | undefined;
mkdtempSync(prefix: string, options?: opts.IOptions): misc.TDataOut;
openSync(path: misc.PathLike, flags: misc.TFlags, mode?: misc.TMode): number;
opendirSync(path: misc.PathLike, options?: opts.IOpendirOptions): misc.IDir;
readdirSync(path: misc.PathLike, options?: opts.IReaddirOptions | string): misc.TDataOut[] | misc.IDirent[];
readlinkSync(path: misc.PathLike, options?: opts.IOptions): misc.TDataOut;
readSync(fd: number, buffer: Buffer | ArrayBufferView | DataView, offset: number, length: number, position: number): number;
readFileSync(file: misc.TFileId, options?: opts.IReadFileOptions | string): misc.TDataOut;
readvSync(fd: number, buffers: ArrayBufferView[], position?: number | null): number;
realpathSync(path: misc.PathLike, options?: opts.IRealpathOptions | string): misc.TDataOut;
renameSync(oldPath: misc.PathLike, newPath: misc.PathLike): void;
rmdirSync(path: misc.PathLike, options?: opts.IRmdirOptions): void;
rmSync(path: misc.PathLike, options?: opts.IRmOptions): void;
statSync(path: misc.PathLike, options: {
bigint: false;
throwIfNoEntry: false;

@@ -57,47 +86,24 @@ }): misc.IStats<number> | undefined;

bigint: true;
throwIfNoEntry: false;
}): misc.IStats<bigint> | undefined;
statSync(path: misc.PathLike, options: {
bigint: true;
throwIfNoEntry?: true;
}): misc.IStats<bigint>;
statSync(path: misc.PathLike, options: {
bigint: false;
throwIfNoEntry: false;
}): misc.IStats<number> | undefined;
statSync(path: misc.PathLike, options: {
bigint: true;
throwIfNoEntry: false;
}): misc.IStats<bigint> | undefined;
fstatSync(fd: number): misc.IStats<number>;
fstatSync(fd: number, options: {
bigint: false;
throwIfNoEntry?: true;
}): misc.IStats<number>;
fstatSync(fd: number, options: {
bigint: true;
}): misc.IStats<bigint>;
renameSync(oldPath: misc.PathLike, newPath: misc.PathLike): void;
existsSync(path: misc.PathLike): boolean;
accessSync(path: misc.PathLike, mode?: number): void;
appendFileSync(id: misc.TFileId, data: misc.TData, options?: opts.IAppendFileOptions | string): void;
readdirSync(path: misc.PathLike, options?: opts.IReaddirOptions | string): misc.TDataOut[] | misc.IDirent[];
readlinkSync(path: misc.PathLike, options?: opts.IOptions): misc.TDataOut;
fsyncSync(fd: number): void;
fdatasyncSync(fd: number): void;
ftruncateSync(fd: number, len?: number): void;
statSync(path: misc.PathLike): misc.IStats<number>;
statfsSync(path: misc.PathLike, options?: opts.IStafsOptions): misc.IStatFs;
symlinkSync(target: misc.PathLike, path: misc.PathLike, type?: misc.symlink.Type): void;
truncateSync(id: misc.TFileId, len?: number): void;
futimesSync(fd: number, atime: misc.TTime, mtime: misc.TTime): void;
unlinkSync(path: misc.PathLike): void;
utimesSync(path: misc.PathLike, atime: misc.TTime, mtime: misc.TTime): void;
mkdirSync(path: misc.PathLike, options: opts.IMkdirOptions & {
recursive: true;
}): string | undefined;
mkdirSync(path: misc.PathLike, options?: misc.TMode | (opts.IMkdirOptions & {
recursive?: false;
})): void;
mkdirSync(path: misc.PathLike, options?: misc.TMode | opts.IMkdirOptions): string | undefined;
mkdtempSync(prefix: string, options?: opts.IOptions): misc.TDataOut;
rmdirSync(path: misc.PathLike, options?: opts.IRmdirOptions): void;
rmSync(path: misc.PathLike, options?: opts.IRmOptions): void;
fchmodSync(fd: number, mode: misc.TMode): void;
chmodSync(path: misc.PathLike, mode: misc.TMode): void;
lchmodSync(path: misc.PathLike, mode: misc.TMode): void;
fchownSync(fd: number, uid: number, gid: number): void;
chownSync(path: misc.PathLike, uid: number, gid: number): void;
lchownSync(path: misc.PathLike, uid: number, gid: number): void;
writeFileSync(id: misc.TFileId, data: misc.TData, options?: opts.IWriteFileOptions): void;
writeSync(fd: number, buffer: Buffer | ArrayBufferView | DataView, offset?: number, length?: number, position?: number | null): number;
writeSync(fd: number, str: string, position?: number, encoding?: BufferEncoding): number;
writevSync(fd: number, buffers: ArrayBufferView[], position?: number | null): void;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=FsSynchronousApi.js.map
import type { FsSynchronousApi } from './FsSynchronousApi';
import type { FsCallbackApi } from './callback';
import type { FsPromisesApi } from './promises';
import type { FsCallbackApi } from './FsCallbackApi';
import type { FsPromisesApi } from './FsPromisesApi';
export { FsSynchronousApi, FsCallbackApi, FsPromisesApi };

@@ -5,0 +5,0 @@ export interface FsApi extends FsCallbackApi, FsSynchronousApi {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=index.js.map

@@ -20,2 +20,3 @@ /// <reference types="node" />

export type TCallback<TData> = (error?: IError | null, data?: TData) => void;
export type TCallback2<T1, T2> = (error: IError | null, bytesRead?: T1, buffers?: T2) => void;
export interface IError extends Error {

@@ -53,2 +54,21 @@ code?: string;

}
export interface IStatFs<T = TStatNumber> {
bavail: T;
bfree: T;
blocks: T;
bsize: T;
ffree: T;
files: T;
type: T;
}
export interface IDir {
path: string;
close(): Promise<void>;
close(callback?: (err?: Error) => void): void;
closeSync(): void;
read(): Promise<IDirent | null>;
read(callback?: (err: Error | null, dir?: IDirent | null) => void): void;
readSync(): IDirent | null;
[Symbol.asyncIterator](): AsyncIterableIterator<IDirent>;
}
export interface IDirent {

@@ -55,0 +75,0 @@ name: TDataOut;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=misc.js.map

@@ -84,4 +84,66 @@ /// <reference types="node" />

export interface IWatchOptions extends IOptions {
/**
* Indicates whether the process should continue to run as long as files are
* being watched. Default: true.
*/
persistent?: boolean;
/**
* Indicates whether all subdirectories should be watched, or only the current
* directory. This applies when a directory is specified, and only on
* supported platforms (See caveats). Default: false.
*/
recursive?: boolean;
/**
* Allows closing the watcher with an {@link AbortSignal}.
*/
signal?: AbortSignal;
}
export interface ICpOptions {
/** dereference symlinks. Default: false. */
dereference?: boolean;
/**
* When force is false, and the destination exists, throw an error.
* Default: false.
*/
errorOnExist?: boolean;
/**
* Function to filter copied files/directories. Return true to copy the item,
* false to ignore it. Default: undefined.
*/
filter?: (src: string, dest: string) => boolean;
/**
* Overwrite existing file or directory. The copy operation will ignore errors
* if you set this to false and the destination exists. Use the errorOnExist
* option to change this behavior. Default: true.
*/
force?: boolean;
/**
* Integer, modifiers for copy operation. Default: 0. See mode flag of
* `fs.copyFileSync()`.
*/
mode: number;
/** When true timestamps from src will be preserved. Default: false. */
preserveTimestamps: boolean;
/** Copy directories recursively Default: false. */
recursive: boolean;
/** When true, path resolution for symlinks will be skipped. Default: false. */
verbatimSymlinks: boolean;
}
export interface IStafsOptions {
/** Whether the numeric values in the returned `StatFs` object should be bigint. */
bigint?: boolean;
}
export interface IOpenAsBlobOptions {
/** An optional mime type for the blob. */
type?: string;
}
export interface IOpendirOptions extends IOptions {
/**
* Number of directory entries that are buffered internally when reading from
* the directory. Higher values lead to better performance but higher memory
* usage. Default: 32.
*/
bufferSize?: number;
/** Default: false. */
recursive?: boolean;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=options.js.map

@@ -20,3 +20,4 @@ /// <reference types="node" />

export declare const getWriteArgs: (fd: number, a?: unknown, b?: unknown, c?: unknown, d?: unknown, e?: unknown) => [fd: number, dataAsStr: boolean, buf: Buffer, offset: number, length: number, position: number | null, callback: (...args: any[]) => void];
export declare const getWriteSyncArgs: (fd: number, a: string | Buffer | ArrayBufferView | DataView, b?: number, c?: number | BufferEncoding, d?: number) => [fd: number, buf: Buffer, offset: number, length?: number | undefined, position?: number | undefined];
export declare const getWriteSyncArgs: (fd: number, a: string | Buffer | ArrayBufferView | DataView, b?: number, c?: number | BufferEncoding, d?: number | null) => [fd: number, buf: Buffer, offset: number, length?: number | undefined, position?: number | null | undefined];
export declare function bufferToEncoding(buffer: Buffer, encoding?: TEncodingExtended): misc.TDataOut;
export declare const unixify: (filepath: string, stripTrailing?: boolean) => string;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.bufferToEncoding = exports.getWriteSyncArgs = exports.getWriteArgs = exports.bufToUint8 = exports.dataToBuffer = exports.validateFd = exports.isFd = exports.flagsToNumber = exports.genRndStr6 = exports.createError = exports.pathToFilename = exports.nullCheck = exports.modeToNumber = exports.validateCallback = exports.promisify = exports.isWin = void 0;
exports.unixify = exports.bufferToEncoding = exports.getWriteSyncArgs = exports.getWriteArgs = exports.bufToUint8 = exports.dataToBuffer = exports.validateFd = exports.isFd = exports.flagsToNumber = exports.genRndStr6 = exports.createError = exports.pathToFilename = exports.nullCheck = exports.modeToNumber = exports.validateCallback = exports.promisify = exports.isWin = void 0;
const constants_1 = require("./constants");

@@ -278,1 +278,30 @@ const errors = require("../internal/errors");

exports.bufferToEncoding = bufferToEncoding;
const isSeparator = (str, i) => {
let char = str[i];
return i > 0 && (char === '/' || (exports.isWin && char === '\\'));
};
const removeTrailingSeparator = (str) => {
let i = str.length - 1;
if (i < 2)
return str;
while (isSeparator(str, i))
i--;
return str.substr(0, i + 1);
};
const normalizePath = (str, stripTrailing) => {
if (typeof str !== 'string')
throw new TypeError('expected a string');
str = str.replace(/[\\\/]+/g, '/');
if (stripTrailing !== false)
str = removeTrailingSeparator(str);
return str;
};
const unixify = (filepath, stripTrailing = true) => {
if (exports.isWin) {
filepath = normalizePath(filepath, stripTrailing);
return filepath.replace(/^([a-zA-Z]+:|\.\/)/, '');
}
return filepath;
};
exports.unixify = unixify;
//# sourceMappingURL=util.js.map

@@ -43,1 +43,2 @@ "use strict";

exports.default = createProcess();
//# sourceMappingURL=process.js.map

@@ -9,1 +9,2 @@ "use strict";

exports.default = _setImmediate;
//# sourceMappingURL=setImmediate.js.map

@@ -14,1 +14,2 @@ "use strict";

exports.default = setTimeoutUnref;
//# sourceMappingURL=setTimeoutUnref.js.map

@@ -5,3 +5,2 @@ "use strict";

const constants_1 = require("./constants");
const getBigInt_1 = require("./getBigInt");
const { S_IFMT, S_IFDIR, S_IFREG, S_IFBLK, S_IFCHR, S_IFLNK, S_IFIFO, S_IFSOCK } = constants_1.constants;

@@ -15,3 +14,3 @@ /**

const { uid, gid, atime, mtime, ctime } = node;
const getStatNumber = !bigint ? number => number : getBigInt_1.default;
const getStatNumber = !bigint ? number => number : number => BigInt(number);
// Copy all values on Stats from Node, so that if Node values

@@ -68,1 +67,2 @@ // change, values on Stats would still be the old ones,

exports.default = Stats;
//# sourceMappingURL=Stats.js.map

@@ -74,1 +74,2 @@ "use strict";

exports.createVolume = createVolume;
//# sourceMappingURL=volume-localstorage.js.map

@@ -15,4 +15,6 @@ /// <reference types="node" />

import * as opts from './node/types/options';
import { FsCallbackApi } from './node/types/FsCallbackApi';
import { ToTreeOptions } from './print';
import type { PathLike, symlink } from 'fs';
import { FsCallbackApi, WritevCallback } from './node/types/callback';
import type { FsPromisesApi, FsSynchronousApi } from './node/types';
export interface IError extends Error {

@@ -85,3 +87,3 @@ code?: string;

private promisesApi;
get promises(): import("./node/types").FsPromisesApi;
get promises(): FsPromisesApi;
constructor(props?: {});

@@ -113,2 +115,3 @@ createLink(): Link;

fromNestedJSON(json: NestedDirectoryJSON, cwd?: string): void;
toTree(opts?: ToTreeOptions): string;
reset(): void;

@@ -143,4 +146,2 @@ mountSync(mountpoint: string, json: DirectoryJSON): void;

write(fd: number, str: string, position: number, encoding: BufferEncoding, callback: (...args: any[]) => void): any;
writev(fd: number, buffers: ArrayBufferView[], callback: WritevCallback): void;
writev(fd: number, buffers: ArrayBufferView[], position: number | null, callback: WritevCallback): void;
private writeFileBase;

@@ -297,5 +298,2 @@ writeFileSync(id: TFileId, data: TData, options?: opts.IWriteFileOptions): void;

mkdir(path: PathLike, mode: TMode | opts.IMkdirOptions, callback: TCallback<string>): any;
mkdirpSync(path: PathLike, mode?: TMode): string | undefined;
mkdirp(path: PathLike, callback: TCallback<string>): any;
mkdirp(path: PathLike, mode: TMode, callback: TCallback<string>): any;
private mkdtempBase;

@@ -338,2 +336,15 @@ mkdtempSync(prefix: string, options?: opts.IOptions): TDataOut;

watch(path: PathLike, options?: IWatchOptions | string, listener?: (eventType: string, filename: string) => void): FSWatcher;
cpSync: FsSynchronousApi['cpSync'];
lutimesSync: FsSynchronousApi['lutimesSync'];
statfsSync: FsSynchronousApi['statfsSync'];
writevSync: FsSynchronousApi['writevSync'];
readvSync: FsSynchronousApi['readvSync'];
opendirSync: FsSynchronousApi['opendirSync'];
cp: FsCallbackApi['cp'];
lutimes: FsCallbackApi['lutimes'];
statfs: FsCallbackApi['statfs'];
writev: FsCallbackApi['writev'];
readv: FsCallbackApi['readv'];
openAsBlob: FsCallbackApi['openAsBlob'];
opendir: FsCallbackApi['opendir'];
}

@@ -340,0 +351,0 @@ export declare class StatWatcher extends EventEmitter {

@@ -23,1 +23,2 @@ "use strict";

}
//# sourceMappingURL=index.js.map
{
"name": "memfs",
"version": "4.1.0",
"version": "4.2.0",
"description": "In-memory file-system with Node's fs API.",
"keywords": [
"fs",
"filesystem",
"fs.js",
"memory-fs",
"memfs",
"file",
"file system",
"mount",
"memory",
"in-memory",
"virtual",
"test",
"testing",
"mock"
],
"author": {
"name": "streamich",
"url": "https://github.com/streamich"
},
"funding": {
"type": "github",
"url": "https://github.com/sponsors/streamich"
},
"homepage": "https://github.com/streamich/memfs",
"repository": {

@@ -29,6 +22,10 @@ "type": "git",

"files": [
"lib"
"lib",
"dist",
"README.md",
"LICENSE",
"demo/runkit.js"
],
"scripts": {
"build": "tsc -p . && cp src/getBigInt.js lib/",
"build": "tsc -p .",
"clean": "rimraf lib types",

@@ -48,4 +45,29 @@ "prettier": "prettier --ignore-path .gitignore --write \"src/**/*.{ts,js}\"",

"demo:git-fsa": "webpack serve --config ./demo/git-fsa/webpack.config.js",
"demo:git-opfs": "webpack serve --config ./demo/git-opfs/webpack.config.js"
"demo:git-opfs": "webpack serve --config ./demo/git-opfs/webpack.config.js",
"demo:crud-and-cas": "webpack serve --config ./demo/crud-and-cas/webpack.config.js"
},
"keywords": [
"fs",
"filesystem",
"fs.js",
"memory-fs",
"memfs",
"file",
"file system",
"mount",
"memory",
"in-memory",
"virtual",
"test",
"testing",
"mock",
"fsa",
"file system access",
"native file system",
"webfs",
"crudfs",
"opfs",
"casfs",
"content addressable storage"
],
"commitlint": {

@@ -62,2 +84,9 @@ "extends": [

"release": {
"branches": [
"master",
{
"name": "next",
"prerelease": true
}
],
"prepare": [

@@ -87,4 +116,6 @@ "@semantic-release/changelog",

},
"peerDependencies": {
"tslib": "2"
},
"dependencies": {
"fs-monkey": "^1.0.4",
"json-joy": "^9.2.0",

@@ -114,8 +145,8 @@ "thingies": "^1.11.1"

"tar-stream": "^3.1.2",
"ts-jest": "^28.0.5",
"ts-jest": "^29.1.0",
"ts-loader": "^9.4.3",
"ts-node": "^10.8.1",
"tslint": "^5.20.1",
"tslint-config-common": "^1.6.0",
"typescript": "^4.7.4",
"ts-node": "^10.9.1",
"tslint": "^6.1.3",
"tslint-config-common": "^1.6.2",
"typescript": "^5.1.3",
"url": "^0.11.1",

@@ -129,3 +160,13 @@ "util": "^0.12.5",

"node": ">= 4.0.0"
},
"prettier": {
"printWidth": 120,
"tabWidth": 2,
"useTabs": false,
"semi": true,
"singleQuote": true,
"trailingComma": "all",
"bracketSpacing": true,
"arrowParens": "avoid"
}
}

@@ -23,4 +23,8 @@ # memfs

- [In-memory Node.js `fs` API](./docs/node/index.md)
- [`fs` to File System Access API adapter](./docs/fsa/fs-to-fsa.md)
- [File System Access to `fs` adapter](./docs/fsa/fsa-to-fs.md)
- `experimental` [`fs` to File System Access API adapter](./docs/fsa/fs-to-fsa.md)
- `experimental` [File System Access API to `fs` adapter](./docs/fsa/fsa-to-fs.md)
- `experimental` [`crudfs` a CRUD-like file system abstraction](./docs/crudfs/index.md)
- `experimental` [`casfs` Content Addressable Storage file system abstraction](./docs/casfs/index.md)
- [Directory `snapshot` utility](./docs/snapshot/index.md)
- [`print` directory tree to terminal](./docs/print/index.md)

@@ -35,2 +39,3 @@

- [`fs` in browser, synchronous API, writes to real folder](demo/fsa-to-node-sync-tests/README.md)
- [`crudfs` and `casfs` in browser and Node.js interoperability](demo/crud-and-cas/README.md)

@@ -40,13 +45,11 @@

- [`spyfs`][spyfs] - spies on filesystem actions
- [`unionfs`][unionfs] - creates a union of multiple filesystem volumes
- [`fs-monkey`][fs-monkey] - monkey-patches Node's `fs` module and `require` function
- [`linkfs`][linkfs] - redirects filesystem paths
- [`fs-monkey`][fs-monkey] - monkey-patches Node's `fs` module and `require` function
- [`libfs`](https://github.com/streamich/full-js/blob/master/src/lib/fs.ts) - real filesystem (that executes UNIX system calls) implemented in JavaScript
- [`spyfs`][spyfs] - spies on filesystem actions
[memfs]: https://github.com/streamich/memfs
[unionfs]: https://github.com/streamich/unionfs
[fs-monkey]: https://github.com/streamich/fs-monkey
[linkfs]: https://github.com/streamich/linkfs
[spyfs]: https://github.com/streamich/spyfs
[fs-monkey]: https://github.com/streamich/fs-monkey

@@ -53,0 +56,0 @@

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc