memfs
Advanced tools
Comparing version 4.1.0-next.2 to 4.1.0-next.3
@@ -30,1 +30,2 @@ "use strict"; | ||
exports.onlyOnNode20 = nodeMajorVersion >= 20 ? describe : describe.skip; | ||
//# sourceMappingURL=util.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
//# sourceMappingURL=types.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 |
"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 }); | ||
const thingies_1 = require("thingies"); | ||
const crypto_1 = require("crypto"); | ||
const __1 = require("../.."); | ||
@@ -19,108 +8,32 @@ const util_1 = require("../../__tests__/util"); | ||
const CrudCas_1 = require("../CrudCas"); | ||
const util_2 = require("../util"); | ||
const hash = (blob) => __awaiter(void 0, void 0, void 0, function* () { | ||
const shasum = (0, crypto_1.createHash)('sha1'); | ||
shasum.update(blob); | ||
return shasum.digest('hex'); | ||
const testCasfs_1 = require("./testCasfs"); | ||
const NodeCrud_1 = require("../../node-to-crud/NodeCrud"); | ||
(0, util_1.onlyOnNode20)('CrudCas on FsaCrud', () => { | ||
const setup = () => { | ||
const fs = (0, __1.memfs)(); | ||
const fsa = new node_to_fsa_1.NodeFileSystemDirectoryHandle(fs, '/', { mode: 'readwrite' }); | ||
const crud = new FsaCrud_1.FsaCrud(fsa); | ||
const cas = new CrudCas_1.CrudCas(crud, { hash: testCasfs_1.hash }); | ||
return { fs, fsa, crud, cas, snapshot: () => fs.__vol.toJSON() }; | ||
}; | ||
(0, testCasfs_1.testCasfs)(setup); | ||
}); | ||
const setup = () => { | ||
const fs = (0, __1.memfs)(); | ||
const fsa = new node_to_fsa_1.NodeFileSystemDirectoryHandle(fs, '/', { mode: 'readwrite' }); | ||
const crud = new FsaCrud_1.FsaCrud(fsa); | ||
const cas = new CrudCas_1.CrudCas(crud, { hash }); | ||
return { fs, fsa, crud, cas, snapshot: () => fs.__vol.toJSON() }; | ||
}; | ||
const b = (str) => { | ||
const buf = Buffer.from(str); | ||
return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength); | ||
}; | ||
(0, util_1.onlyOnNode20)('CrudCas', () => { | ||
describe('.put()', () => { | ||
test('can store a blob', () => __awaiter(void 0, void 0, void 0, function* () { | ||
const blob = b('hello world'); | ||
const { cas, snapshot } = setup(); | ||
const hash = yield cas.put(blob); | ||
expect(hash).toBe('2aae6c35c94fcfb415dbe95f408b9ce91ee846ed'); | ||
expect(snapshot()).toMatchSnapshot(); | ||
})); | ||
}); | ||
describe('.get()', () => { | ||
test('can retrieve existing blob', () => __awaiter(void 0, void 0, void 0, function* () { | ||
const blob = b('hello world'); | ||
const { cas } = setup(); | ||
const hash = yield cas.put(blob); | ||
const blob2 = yield cas.get(hash); | ||
expect(blob2).toStrictEqual(blob); | ||
})); | ||
test('throws if blob does not exist', () => __awaiter(void 0, void 0, void 0, function* () { | ||
const blob = b('hello world 2'); | ||
const { cas } = setup(); | ||
const hash = yield cas.put(blob); | ||
const [, err] = yield (0, thingies_1.of)(cas.get('2aae6c35c94fcfb415dbe95f408b9ce91ee846ed')); | ||
expect(err).toBeInstanceOf(DOMException); | ||
expect(err.name).toBe('BlobNotFound'); | ||
})); | ||
test('throws if blob contents does not match the hash', () => __awaiter(void 0, void 0, void 0, function* () { | ||
const blob = b('hello world'); | ||
const { cas, crud } = setup(); | ||
const hash = yield cas.put(blob); | ||
const location = (0, util_2.hashToLocation)(hash); | ||
yield crud.put(location[0], location[1], b('hello world!')); | ||
const [, err] = yield (0, thingies_1.of)(cas.get(hash)); | ||
expect(err).toBeInstanceOf(DOMException); | ||
expect(err.name).toBe('Integrity'); | ||
})); | ||
test('does not throw if integrity check is skipped', () => __awaiter(void 0, void 0, void 0, function* () { | ||
const blob = b('hello world'); | ||
const { cas, crud } = setup(); | ||
const hash = yield cas.put(blob); | ||
const location = (0, util_2.hashToLocation)(hash); | ||
yield crud.put(location[0], location[1], b('hello world!')); | ||
const blob2 = yield cas.get(hash, { skipVerification: true }); | ||
expect(blob2).toStrictEqual(b('hello world!')); | ||
})); | ||
}); | ||
describe('.info()', () => { | ||
test('can retrieve existing blob info', () => __awaiter(void 0, void 0, void 0, function* () { | ||
const blob = b('hello world'); | ||
const { cas } = setup(); | ||
const hash = yield cas.put(blob); | ||
const info = yield cas.info(hash); | ||
expect(info.size).toBe(11); | ||
})); | ||
test('throws if blob does not exist', () => __awaiter(void 0, void 0, void 0, function* () { | ||
const blob = b('hello world 2'); | ||
const { cas } = setup(); | ||
const hash = yield cas.put(blob); | ||
const [, err] = yield (0, thingies_1.of)(cas.info('2aae6c35c94fcfb415dbe95f408b9ce91ee846ed')); | ||
expect(err).toBeInstanceOf(DOMException); | ||
expect(err.name).toBe('BlobNotFound'); | ||
})); | ||
}); | ||
describe('.del()', () => { | ||
test('can delete an existing blob', () => __awaiter(void 0, void 0, void 0, function* () { | ||
const blob = b('hello world'); | ||
const { cas } = setup(); | ||
const hash = yield cas.put(blob); | ||
const info = yield cas.info(hash); | ||
yield cas.del(hash); | ||
const [, err] = yield (0, thingies_1.of)(cas.info(hash)); | ||
expect(err).toBeInstanceOf(DOMException); | ||
expect(err.name).toBe('BlobNotFound'); | ||
})); | ||
test('throws if blob does not exist', () => __awaiter(void 0, void 0, void 0, function* () { | ||
const blob = b('hello world 2'); | ||
const { cas } = setup(); | ||
const hash = yield cas.put(blob); | ||
const [, err] = yield (0, thingies_1.of)(cas.del('2aae6c35c94fcfb415dbe95f408b9ce91ee846ed')); | ||
expect(err).toBeInstanceOf(DOMException); | ||
expect(err.name).toBe('BlobNotFound'); | ||
})); | ||
test('does not throw if "silent" flag is provided', () => __awaiter(void 0, void 0, void 0, function* () { | ||
const blob = b('hello world 2'); | ||
const { cas } = setup(); | ||
const hash = yield cas.put(blob); | ||
yield cas.del('2aae6c35c94fcfb415dbe95f408b9ce91ee846ed', true); | ||
})); | ||
}); | ||
(0, util_1.onlyOnNode20)('CrudCas on NodeCrud at root', () => { | ||
const setup = () => { | ||
const fs = (0, __1.memfs)(); | ||
const crud = new NodeCrud_1.NodeCrud({ fs: fs.promises, dir: '/' }); | ||
const cas = new CrudCas_1.CrudCas(crud, { hash: testCasfs_1.hash }); | ||
return { fs, crud, cas, snapshot: () => fs.__vol.toJSON() }; | ||
}; | ||
(0, testCasfs_1.testCasfs)(setup); | ||
}); | ||
(0, util_1.onlyOnNode20)('CrudCas on NodeCrud at in sub-folder', () => { | ||
const setup = () => { | ||
const fs = (0, __1.memfs)({ '/a/b/c': null }); | ||
const crud = new NodeCrud_1.NodeCrud({ fs: fs.promises, dir: '/a/b/c' }); | ||
const cas = new CrudCas_1.CrudCas(crud, { hash: testCasfs_1.hash }); | ||
return { fs, crud, cas, snapshot: () => fs.__vol.toJSON() }; | ||
}; | ||
(0, testCasfs_1.testCasfs)(setup); | ||
}); | ||
//# sourceMappingURL=CrudCas.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 }); | ||
exports.CrudCas = void 0; | ||
const tslib_1 = require("tslib"); | ||
const util_1 = require("./util"); | ||
const normalizeErrors = (code) => __awaiter(void 0, void 0, void 0, function* () { | ||
const normalizeErrors = (code) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
try { | ||
@@ -33,3 +25,3 @@ return yield code(); | ||
this.options = options; | ||
this.put = (blob) => __awaiter(this, void 0, void 0, function* () { | ||
this.put = (blob) => tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const digest = yield this.options.hash(blob); | ||
@@ -40,5 +32,5 @@ const [collection, resource] = (0, util_1.hashToLocation)(digest); | ||
}); | ||
this.get = (hash, options) => __awaiter(this, void 0, void 0, function* () { | ||
this.get = (hash, options) => tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const [collection, resource] = (0, util_1.hashToLocation)(hash); | ||
return yield normalizeErrors(() => __awaiter(this, void 0, void 0, function* () { | ||
return yield normalizeErrors(() => tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const blob = yield this.crud.get(collection, resource); | ||
@@ -53,11 +45,11 @@ if (!(options === null || options === void 0 ? void 0 : options.skipVerification)) { | ||
}); | ||
this.del = (hash, silent) => __awaiter(this, void 0, void 0, function* () { | ||
this.del = (hash, silent) => tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const [collection, resource] = (0, util_1.hashToLocation)(hash); | ||
yield normalizeErrors(() => __awaiter(this, void 0, void 0, function* () { | ||
yield normalizeErrors(() => tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
return yield this.crud.del(collection, resource, silent); | ||
})); | ||
}); | ||
this.info = (hash) => __awaiter(this, void 0, void 0, function* () { | ||
this.info = (hash) => tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const [collection, resource] = (0, util_1.hashToLocation)(hash); | ||
return yield normalizeErrors(() => __awaiter(this, void 0, void 0, function* () { | ||
return yield normalizeErrors(() => tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
return yield this.crud.info(collection, resource); | ||
@@ -69,1 +61,2 @@ })); | ||
exports.CrudCas = CrudCas; | ||
//# sourceMappingURL=CrudCas.js.map |
@@ -13,1 +13,2 @@ "use strict"; | ||
exports.hashToLocation = hashToLocation; | ||
//# sourceMappingURL=util.js.map |
@@ -51,2 +51,9 @@ export interface CrudApi { | ||
list: (collection: CrudCollection) => Promise<CrudCollectionEntry[]>; | ||
/** | ||
* Creates a new CrudApi instance, with the given collection as root. | ||
* | ||
* @param collection Type of the resource, collection name. | ||
* @returns A new CrudApi instance, with the given collection as root. | ||
*/ | ||
from: (collection: CrudCollection) => Promise<CrudApi>; | ||
} | ||
@@ -53,0 +60,0 @@ export type CrudCollection = string[]; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
//# sourceMappingURL=types.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 |
"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 }); | ||
const thingies_1 = require("thingies"); | ||
const __1 = require("../.."); | ||
@@ -17,2 +7,3 @@ const util_1 = require("../../__tests__/util"); | ||
const FsaCrud_1 = require("../FsaCrud"); | ||
const testCrudfs_1 = require("../../crud/__tests__/testCrudfs"); | ||
const setup = () => { | ||
@@ -24,273 +15,5 @@ const fs = (0, __1.memfs)(); | ||
}; | ||
const b = (str) => { | ||
const buf = Buffer.from(str); | ||
return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength); | ||
}; | ||
(0, util_1.onlyOnNode20)('FsaCrud', () => { | ||
describe('.put()', () => { | ||
test('throws if the type is not valid', () => __awaiter(void 0, void 0, void 0, function* () { | ||
const { crud } = setup(); | ||
const [, err] = yield (0, thingies_1.of)(crud.put(['.', 'foo'], 'bar', new Uint8Array())); | ||
expect(err).toBeInstanceOf(TypeError); | ||
expect(err.message).toBe("Failed to execute 'put' on 'crudfs': Name is not allowed."); | ||
})); | ||
test('throws if id is not valid', () => __awaiter(void 0, void 0, void 0, function* () { | ||
const { crud } = setup(); | ||
const [, err] = yield (0, thingies_1.of)(crud.put(['foo'], '..', new Uint8Array())); | ||
expect(err).toBeInstanceOf(TypeError); | ||
expect(err.message).toBe("Failed to execute 'put' on 'crudfs': Name is not allowed."); | ||
})); | ||
test('can store a resource at root', () => __awaiter(void 0, void 0, void 0, function* () { | ||
const { crud, snapshot } = setup(); | ||
yield crud.put([], 'bar', b('abc')); | ||
expect(snapshot()).toStrictEqual({ | ||
'/bar': 'abc', | ||
}); | ||
})); | ||
test('can store a resource in two levels deep collection', () => __awaiter(void 0, void 0, void 0, function* () { | ||
const { crud, snapshot } = setup(); | ||
yield crud.put(['a', 'b'], 'bar', b('abc')); | ||
expect(snapshot()).toStrictEqual({ | ||
'/a/b/bar': 'abc', | ||
}); | ||
})); | ||
test('can overwrite existing resource', () => __awaiter(void 0, void 0, void 0, function* () { | ||
const { crud, snapshot } = setup(); | ||
yield crud.put(['a', 'b'], 'bar', b('abc')); | ||
yield crud.put(['a', 'b'], 'bar', b('efg')); | ||
expect(snapshot()).toStrictEqual({ | ||
'/a/b/bar': 'efg', | ||
}); | ||
})); | ||
test('can choose to throw if item already exists', () => __awaiter(void 0, void 0, void 0, function* () { | ||
const { crud } = setup(); | ||
yield crud.put(['a', 'b'], 'bar', b('abc'), { throwIf: 'exists' }); | ||
const [, err] = yield (0, thingies_1.of)(crud.put(['a', 'b'], 'bar', b('efg'), { throwIf: 'exists' })); | ||
expect(err).toBeInstanceOf(DOMException); | ||
expect(err.name).toBe('Exists'); | ||
})); | ||
test('can choose to throw if item does not exist', () => __awaiter(void 0, void 0, void 0, function* () { | ||
const { crud, snapshot } = setup(); | ||
const [, err] = yield (0, thingies_1.of)(crud.put(['a', 'b'], 'bar', b('1'), { throwIf: 'missing' })); | ||
yield crud.put(['a', 'b'], 'bar', b('2')); | ||
yield crud.put(['a', 'b'], 'bar', b('3'), { throwIf: 'missing' }); | ||
expect(err).toBeInstanceOf(DOMException); | ||
expect(err.name).toBe('Missing'); | ||
expect(snapshot()).toStrictEqual({ | ||
'/a/b/bar': '3', | ||
}); | ||
})); | ||
}); | ||
describe('.get()', () => { | ||
test('throws if the type is not valid', () => __awaiter(void 0, void 0, void 0, function* () { | ||
const { crud } = setup(); | ||
const [, err] = yield (0, thingies_1.of)(crud.get(['', 'foo'], 'bar')); | ||
expect(err).toBeInstanceOf(TypeError); | ||
expect(err.message).toBe("Failed to execute 'get' on 'crudfs': Name is not allowed."); | ||
})); | ||
test('throws if id is not valid', () => __awaiter(void 0, void 0, void 0, function* () { | ||
const { crud } = setup(); | ||
const [, err] = yield (0, thingies_1.of)(crud.get(['foo'], '')); | ||
expect(err).toBeInstanceOf(TypeError); | ||
expect(err.message).toBe("Failed to execute 'get' on 'crudfs': Name is not allowed."); | ||
})); | ||
test('throws if collection does not exist', () => __awaiter(void 0, void 0, void 0, function* () { | ||
const { crud } = setup(); | ||
const [, err] = yield (0, thingies_1.of)(crud.get(['foo'], 'bar')); | ||
expect(err).toBeInstanceOf(DOMException); | ||
expect(err.name).toBe('CollectionNotFound'); | ||
})); | ||
test('throws if resource does not exist', () => __awaiter(void 0, void 0, void 0, function* () { | ||
const { crud } = setup(); | ||
yield crud.put(['foo'], 'bar', b('abc')); | ||
const [, err] = yield (0, thingies_1.of)(crud.get(['foo'], 'baz')); | ||
expect(err).toBeInstanceOf(DOMException); | ||
expect(err.name).toBe('ResourceNotFound'); | ||
})); | ||
test('can fetch an existing resource', () => __awaiter(void 0, void 0, void 0, function* () { | ||
const { crud } = setup(); | ||
yield crud.put(['foo'], 'bar', b('abc')); | ||
const blob = yield crud.get(['foo'], 'bar'); | ||
expect(blob).toStrictEqual(b('abc')); | ||
})); | ||
}); | ||
describe('.del()', () => { | ||
test('throws if the type is not valid', () => __awaiter(void 0, void 0, void 0, function* () { | ||
const { crud } = setup(); | ||
const [, err] = yield (0, thingies_1.of)(crud.del(['sdf\\dd', 'foo'], 'bar')); | ||
expect(err).toBeInstanceOf(TypeError); | ||
expect(err.message).toBe("Failed to execute 'del' on 'crudfs': Name is not allowed."); | ||
})); | ||
test('throws if id is not valid', () => __awaiter(void 0, void 0, void 0, function* () { | ||
const { crud } = setup(); | ||
const [, err] = yield (0, thingies_1.of)(crud.del(['foo'], 'asdf/asdf')); | ||
expect(err).toBeInstanceOf(TypeError); | ||
expect(err.message).toBe("Failed to execute 'del' on 'crudfs': Name is not allowed."); | ||
})); | ||
describe('when collection does not exist', () => { | ||
test('throws by default', () => __awaiter(void 0, void 0, void 0, function* () { | ||
const { crud } = setup(); | ||
const [, err] = yield (0, thingies_1.of)(crud.del(['foo'], 'bar')); | ||
expect(err).toBeInstanceOf(DOMException); | ||
expect(err.name).toBe('CollectionNotFound'); | ||
})); | ||
test('does not throw when "silent" flag set', () => __awaiter(void 0, void 0, void 0, function* () { | ||
const { crud } = setup(); | ||
yield crud.del(['foo'], 'bar', true); | ||
})); | ||
}); | ||
describe('when collection is found but resource is not', () => { | ||
test('throws by default', () => __awaiter(void 0, void 0, void 0, function* () { | ||
const { crud } = setup(); | ||
yield crud.put(['foo'], 'bar', b('abc')); | ||
const [, err] = yield (0, thingies_1.of)(crud.del(['foo'], 'baz')); | ||
expect(err).toBeInstanceOf(DOMException); | ||
expect(err.name).toBe('ResourceNotFound'); | ||
})); | ||
test('does not throw when "silent" flag set', () => __awaiter(void 0, void 0, void 0, function* () { | ||
const { crud } = setup(); | ||
yield crud.put(['foo'], 'bar', b('abc')); | ||
yield crud.del(['foo'], 'baz', true); | ||
})); | ||
}); | ||
test('deletes an existing resource', () => __awaiter(void 0, void 0, void 0, function* () { | ||
const { crud } = setup(); | ||
yield crud.put(['foo'], 'bar', b('abc')); | ||
yield crud.get(['foo'], 'bar'); | ||
yield crud.del(['foo'], 'bar'); | ||
const [, err] = yield (0, thingies_1.of)(crud.get(['foo'], 'bar')); | ||
expect(err).toBeInstanceOf(DOMException); | ||
expect(err.name).toBe('ResourceNotFound'); | ||
})); | ||
}); | ||
describe('.info()', () => { | ||
test('throws if the type is not valid', () => __awaiter(void 0, void 0, void 0, function* () { | ||
const { crud } = setup(); | ||
const [, err] = yield (0, thingies_1.of)(crud.info(['', 'foo'], 'bar')); | ||
expect(err).toBeInstanceOf(TypeError); | ||
expect(err.message).toBe("Failed to execute 'info' on 'crudfs': Name is not allowed."); | ||
})); | ||
test('throws if id is not valid', () => __awaiter(void 0, void 0, void 0, function* () { | ||
const { crud } = setup(); | ||
const [, err] = yield (0, thingies_1.of)(crud.info(['foo'], '/')); | ||
expect(err).toBeInstanceOf(TypeError); | ||
expect(err.message).toBe("Failed to execute 'info' on 'crudfs': Name is not allowed."); | ||
})); | ||
test('can retrieve information about a resource', () => __awaiter(void 0, void 0, void 0, function* () { | ||
const { crud } = setup(); | ||
yield crud.put(['foo'], 'bar', b('abc')); | ||
const info = yield crud.info(['foo'], 'bar'); | ||
expect(info).toMatchObject({ | ||
type: 'resource', | ||
id: 'bar', | ||
size: 3, | ||
modified: expect.any(Number), | ||
}); | ||
})); | ||
test('can retrieve information about a collection', () => __awaiter(void 0, void 0, void 0, function* () { | ||
const { crud } = setup(); | ||
yield crud.put(['foo'], 'bar', b('abc')); | ||
const info = yield crud.info(['foo']); | ||
expect(info).toMatchObject({ | ||
type: 'collection', | ||
}); | ||
})); | ||
test('throws when resource not found', () => __awaiter(void 0, void 0, void 0, function* () { | ||
const { crud } = setup(); | ||
yield crud.put(['foo'], 'bar', b('abc')); | ||
const [, err] = yield (0, thingies_1.of)(crud.info(['foo'], 'baz')); | ||
expect(err).toBeInstanceOf(DOMException); | ||
expect(err.name).toBe('ResourceNotFound'); | ||
})); | ||
test('throws when collection not found', () => __awaiter(void 0, void 0, void 0, function* () { | ||
const { crud } = setup(); | ||
yield crud.put(['foo', 'a'], 'bar', b('abc')); | ||
const [, err] = yield (0, thingies_1.of)(crud.info(['foo', 'b'], 'baz')); | ||
expect(err).toBeInstanceOf(DOMException); | ||
expect(err.name).toBe('CollectionNotFound'); | ||
})); | ||
}); | ||
describe('.drop()', () => { | ||
test('throws if the collection is not valid', () => __awaiter(void 0, void 0, void 0, function* () { | ||
const { crud } = setup(); | ||
const [, err] = yield (0, thingies_1.of)(crud.drop(['', 'foo'])); | ||
expect(err).toBeInstanceOf(TypeError); | ||
expect(err.message).toBe("Failed to execute 'drop' on 'crudfs': Name is not allowed."); | ||
})); | ||
test('can recursively delete a collection', () => __awaiter(void 0, void 0, void 0, function* () { | ||
const { crud } = setup(); | ||
yield crud.put(['foo', 'a'], 'bar', b('1')); | ||
yield crud.put(['foo', 'a'], 'baz', b('2')); | ||
yield crud.put(['foo', 'b'], 'xyz', b('3')); | ||
const info = yield crud.info(['foo', 'a']); | ||
expect(info.type).toBe('collection'); | ||
yield crud.drop(['foo', 'a']); | ||
const [, err] = yield (0, thingies_1.of)(crud.info(['foo', 'a'])); | ||
expect(err).toBeInstanceOf(DOMException); | ||
expect(err.name).toBe('CollectionNotFound'); | ||
})); | ||
test('throws if collection does not exist', () => __awaiter(void 0, void 0, void 0, function* () { | ||
const { crud } = setup(); | ||
yield crud.put(['foo', 'a'], 'bar', b('1')); | ||
yield crud.put(['foo', 'a'], 'baz', b('2')); | ||
yield crud.put(['foo', 'b'], 'xyz', b('3')); | ||
const [, err] = yield (0, thingies_1.of)(crud.drop(['gg'])); | ||
expect(err).toBeInstanceOf(DOMException); | ||
expect(err.name).toBe('CollectionNotFound'); | ||
})); | ||
test('when "silent" flag set, does not throw if collection does not exist', () => __awaiter(void 0, void 0, void 0, function* () { | ||
const { crud } = setup(); | ||
yield crud.put(['foo', 'a'], 'bar', b('1')); | ||
yield crud.put(['foo', 'a'], 'baz', b('2')); | ||
yield crud.put(['foo', 'b'], 'xyz', b('3')); | ||
yield crud.drop(['gg'], true); | ||
})); | ||
test('can recursively delete everything from root', () => __awaiter(void 0, void 0, void 0, function* () { | ||
const { crud, snapshot } = setup(); | ||
yield crud.put(['foo', 'a'], 'bar', b('1')); | ||
yield crud.put(['baz', 'a'], 'baz', b('2')); | ||
yield crud.put(['bar', 'b'], 'xyz', b('3')); | ||
const info = yield crud.info(['foo', 'a']); | ||
expect(info.type).toBe('collection'); | ||
yield crud.drop([]); | ||
expect(snapshot()).toEqual({}); | ||
})); | ||
}); | ||
describe('.list()', () => { | ||
test('throws if the collection is not valid', () => __awaiter(void 0, void 0, void 0, function* () { | ||
const { crud } = setup(); | ||
const [, err] = yield (0, thingies_1.of)(crud.list(['./..', 'foo'])); | ||
expect(err).toBeInstanceOf(TypeError); | ||
expect(err.message).toBe("Failed to execute 'drop' on 'crudfs': Name is not allowed."); | ||
})); | ||
test('can retrieve a list of resources and collections at root', () => __awaiter(void 0, void 0, void 0, function* () { | ||
const { crud } = setup(); | ||
yield crud.put(['foo'], 'bar', b('1')); | ||
yield crud.put([], 'baz', b('1')); | ||
yield crud.put([], 'qux', b('2')); | ||
const list = yield crud.list([]); | ||
expect(list.length).toBe(3); | ||
expect(list.find(x => x.id === 'baz')).toMatchObject({ | ||
type: 'resource', | ||
id: 'baz', | ||
}); | ||
expect(list.find(x => x.id === 'qux')).toMatchObject({ | ||
type: 'resource', | ||
id: 'qux', | ||
}); | ||
expect(list.find(x => x.id === 'foo')).toMatchObject({ | ||
type: 'collection', | ||
id: 'foo', | ||
}); | ||
})); | ||
test('throws when try to list a non-existing collection', () => __awaiter(void 0, void 0, void 0, function* () { | ||
const { crud } = setup(); | ||
yield crud.put(['foo'], 'bar', b('1')); | ||
yield crud.put([], 'baz', b('1')); | ||
yield crud.put([], 'qux', b('2')); | ||
const [, err] = yield (0, thingies_1.of)(crud.list(['gg'])); | ||
expect(err).toBeInstanceOf(DOMException); | ||
expect(err.name).toBe('CollectionNotFound'); | ||
})); | ||
}); | ||
(0, testCrudfs_1.testCrudfs)(setup); | ||
}); | ||
//# sourceMappingURL=FsaCrud.test.js.map |
@@ -14,2 +14,3 @@ import type * as crud from '../crud/types'; | ||
readonly list: (collection: crud.CrudCollection) => Promise<crud.CrudCollectionEntry[]>; | ||
readonly from: (collection: crud.CrudCollection) => Promise<crud.CrudApi>; | ||
} |
"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.FsaCrud = void 0; | ||
const tslib_1 = require("tslib"); | ||
const util_1 = require("../node-to-fsa/util"); | ||
const util_2 = require("./util"); | ||
const util_2 = require("../crud/util"); | ||
const util_3 = require("./util"); | ||
class FsaCrud { | ||
constructor(root) { | ||
this.root = root; | ||
this.put = (collection, id, data, options) => __awaiter(this, void 0, void 0, function* () { | ||
this.put = (collection, id, data, options) => tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
(0, util_2.assertType)(collection, 'put', 'crudfs'); | ||
@@ -34,3 +20,3 @@ (0, util_1.assertName)(id, 'put', 'crudfs'); | ||
file = yield dir.getFileHandle(id, { create: false }); | ||
throw new DOMException('Resource already exists', 'Exists'); | ||
throw (0, util_3.newExistsError)(); | ||
} | ||
@@ -50,3 +36,3 @@ catch (e) { | ||
if (e.name === 'NotFoundError') | ||
throw new DOMException('Resource is missing', 'Missing'); | ||
throw (0, util_3.newMissingError)(); | ||
throw e; | ||
@@ -64,3 +50,3 @@ } | ||
}); | ||
this.get = (collection, id) => __awaiter(this, void 0, void 0, function* () { | ||
this.get = (collection, id) => tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
(0, util_2.assertType)(collection, 'get', 'crudfs'); | ||
@@ -73,3 +59,3 @@ (0, util_1.assertName)(id, 'get', 'crudfs'); | ||
}); | ||
this.del = (collection, id, silent) => __awaiter(this, void 0, void 0, function* () { | ||
this.del = (collection, id, silent) => tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
(0, util_2.assertType)(collection, 'del', 'crudfs'); | ||
@@ -86,3 +72,3 @@ (0, util_1.assertName)(id, 'del', 'crudfs'); | ||
}); | ||
this.info = (collection, id) => __awaiter(this, void 0, void 0, function* () { | ||
this.info = (collection, id) => tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
(0, util_2.assertType)(collection, 'info', 'crudfs'); | ||
@@ -108,3 +94,3 @@ if (id) { | ||
}); | ||
this.drop = (collection, silent) => __awaiter(this, void 0, void 0, function* () { | ||
this.drop = (collection, silent) => tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
var _a, e_1, _b, _c; | ||
@@ -120,12 +106,7 @@ (0, util_2.assertType)(collection, 'drop', 'crudfs'); | ||
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 = yield _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; | ||
yield root.removeEntry(name, { recursive: true }); | ||
} | ||
@@ -147,3 +128,3 @@ } | ||
}); | ||
this.list = (collection) => __awaiter(this, void 0, void 0, function* () { | ||
this.list = (collection) => tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
var _g, e_2, _h, _j; | ||
@@ -154,22 +135,17 @@ (0, util_2.assertType)(collection, 'drop', 'crudfs'); | ||
try { | ||
for (var _k = true, _l = __asyncValues(dir.entries()), _m; _m = yield _l.next(), _g = _m.done, !_g;) { | ||
for (var _k = true, _l = tslib_1.__asyncValues(dir.entries()), _m; _m = yield _l.next(), _g = _m.done, !_g; _k = true) { | ||
_j = _m.value; | ||
_k = false; | ||
try { | ||
const [id, handle] = _j; | ||
if (handle.kind === 'file') { | ||
entries.push({ | ||
type: 'resource', | ||
id, | ||
}); | ||
} | ||
else if (handle.kind === 'directory') { | ||
entries.push({ | ||
type: 'collection', | ||
id, | ||
}); | ||
} | ||
const [id, handle] = _j; | ||
if (handle.kind === 'file') { | ||
entries.push({ | ||
type: 'resource', | ||
id, | ||
}); | ||
} | ||
finally { | ||
_k = true; | ||
else if (handle.kind === 'directory') { | ||
entries.push({ | ||
type: 'collection', | ||
id, | ||
}); | ||
} | ||
@@ -187,5 +163,10 @@ } | ||
}); | ||
this.from = (collection) => tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
(0, util_2.assertType)(collection, 'from', 'crudfs'); | ||
const [dir] = yield this.getDir(collection, true); | ||
return new FsaCrud(dir); | ||
}); | ||
} | ||
getDir(collection, create) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
let parent = undefined; | ||
@@ -203,3 +184,3 @@ let dir = yield this.root; | ||
if (error.name === 'NotFoundError') | ||
throw new DOMException(`Collection /${collection.join('/')} does not exist`, 'CollectionNotFound'); | ||
throw (0, util_3.newFolder404Error)(collection); | ||
throw error; | ||
@@ -210,3 +191,3 @@ } | ||
getFile(collection, id) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const [dir] = yield this.getDir(collection, false); | ||
@@ -219,3 +200,3 @@ try { | ||
if (error.name === 'NotFoundError') | ||
throw new DOMException(`Resource "${id}" in /${collection.join('/')} not found`, 'ResourceNotFound'); | ||
throw (0, util_3.newFile404Error)(collection, id); | ||
throw error; | ||
@@ -227,1 +208,2 @@ } | ||
exports.FsaCrud = FsaCrud; | ||
//# sourceMappingURL=FsaCrud.js.map |
@@ -1,2 +0,5 @@ | ||
import { CrudCollection } from '../crud/types'; | ||
export declare const assertType: (type: CrudCollection, method: string, klass: string) => void; | ||
import type * as crud from '../crud/types'; | ||
export declare const newFile404Error: (collection: crud.CrudCollection, id: string) => DOMException; | ||
export declare const newFolder404Error: (collection: crud.CrudCollection) => DOMException; | ||
export declare const newExistsError: () => DOMException; | ||
export declare const newMissingError: () => DOMException; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.assertType = void 0; | ||
const util_1 = require("../node-to-fsa/util"); | ||
const assertType = (type, method, klass) => { | ||
const length = type.length; | ||
for (let i = 0; i < length; i++) | ||
(0, util_1.assertName)(type[i], method, klass); | ||
}; | ||
exports.assertType = assertType; | ||
exports.newMissingError = exports.newExistsError = exports.newFolder404Error = exports.newFile404Error = void 0; | ||
const newFile404Error = (collection, id) => new DOMException(`Resource "${id}" in /${collection.join('/')} not found`, 'ResourceNotFound'); | ||
exports.newFile404Error = newFile404Error; | ||
const newFolder404Error = (collection) => new DOMException(`Collection /${collection.join('/')} does not exist`, 'CollectionNotFound'); | ||
exports.newFolder404Error = newFolder404Error; | ||
const newExistsError = () => new DOMException('Resource already exists', 'Exists'); | ||
exports.newExistsError = newExistsError; | ||
const newMissingError = () => new DOMException('Resource is missing', 'Missing'); | ||
exports.newMissingError = newMissingError; | ||
//# sourceMappingURL=util.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 }); | ||
const tslib_1 = require("tslib"); | ||
const __1 = require("../.."); | ||
@@ -25,3 +17,3 @@ const node_to_fsa_1 = require("../../node-to-fsa"); | ||
describe('.mkdir()', () => { | ||
test('can create a sub-folder', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('can create a sub-folder', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { fs, mfs } = setup(); | ||
@@ -35,3 +27,12 @@ yield new Promise((resolve, reject) => fs.mkdir('/test', err => { | ||
})); | ||
test('throws when creating sub-sub-folder', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('can create a sub-folder with trailing slash', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { fs, mfs } = setup(); | ||
yield 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', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { fs } = setup(); | ||
@@ -50,3 +51,3 @@ try { | ||
})); | ||
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', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { fs, mfs } = setup(); | ||
@@ -60,3 +61,3 @@ yield new Promise((resolve, reject) => fs.mkdir('/test/subtest', { recursive: true }, err => { | ||
})); | ||
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', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { fs, mfs } = setup(); | ||
@@ -66,3 +67,3 @@ yield fs.promises.mkdir('/test/subtest', { recursive: 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', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { fs } = setup({ file: 'test' }); | ||
@@ -79,3 +80,3 @@ try { | ||
describe('.mkdtemp()', () => { | ||
test('can create a temporary folder', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('can create a temporary folder', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { fs, mfs } = setup(); | ||
@@ -88,3 +89,3 @@ const dirname = (yield fs.promises.mkdtemp('prefix--')); | ||
describe('.rmdir()', () => { | ||
test('can remove an empty folder', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('can remove an empty folder', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null }); | ||
@@ -94,3 +95,3 @@ yield fs.promises.rmdir('/empty-folder'); | ||
})); | ||
test('throws when attempts to remove non-empty folder', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('throws when attempts to remove non-empty folder', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null }); | ||
@@ -109,3 +110,3 @@ try { | ||
})); | ||
test('can remove non-empty directory recursively', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('can remove non-empty directory recursively', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { fs, mfs } = setup({ folder: { subfolder: { file: 'test' } }, 'empty-folder': null }); | ||
@@ -117,3 +118,3 @@ yield fs.promises.rmdir('/folder', { recursive: true }); | ||
})); | ||
test('can remove starting from root folder', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('can remove starting from root folder', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { fs, mfs } = setup({ folder: { subfolder: { file: 'test' } }, 'empty-folder': null }); | ||
@@ -127,3 +128,3 @@ yield fs.promises.rmdir('/', { recursive: true }); | ||
describe('.rm()', () => { | ||
test('can remove an empty folder', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('can remove an empty folder', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null }); | ||
@@ -133,3 +134,3 @@ yield fs.promises.rm('/empty-folder'); | ||
})); | ||
test('throws when attempts to remove non-empty folder', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('throws when attempts to remove non-empty folder', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null }); | ||
@@ -148,3 +149,3 @@ try { | ||
})); | ||
test('can remove non-empty directory recursively', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('can remove non-empty directory recursively', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { fs, mfs } = setup({ folder: { subfolder: { file: 'test' } }, 'empty-folder': null }); | ||
@@ -156,3 +157,3 @@ yield fs.promises.rm('/folder', { recursive: true }); | ||
})); | ||
test('throws if path does not exist', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('throws if path does not exist', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { fs, mfs } = setup({ folder: { subfolder: { file: 'test' } }, 'empty-folder': null }); | ||
@@ -171,7 +172,7 @@ try { | ||
})); | ||
test('does not throw, if path does not exist, but "force" flag set', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('does not throw, if path does not exist, but "force" flag set', () => tslib_1.__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* () { | ||
test('can remove a file', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { fs, mfs } = setup({ folder: { subfolder: { file: 'test' } }, 'empty-folder': null }); | ||
@@ -184,3 +185,3 @@ yield fs.promises.rm('/folder/subfolder/file'); | ||
})); | ||
test('can remove starting from root folder', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('can remove starting from root folder', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { fs, mfs } = setup({ folder: { subfolder: { file: 'test' } }, 'empty-folder': null }); | ||
@@ -194,3 +195,3 @@ yield fs.promises.rm('/', { recursive: true }); | ||
describe('.unlink()', () => { | ||
test('can remove a file', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('can remove a file', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null }); | ||
@@ -204,3 +205,3 @@ const res = yield fs.promises.unlink('/folder/file'); | ||
})); | ||
test('cannot delete a folder', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('cannot delete a folder', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null }); | ||
@@ -219,3 +220,3 @@ try { | ||
})); | ||
test('throws when deleting non-existing file', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('throws when deleting non-existing file', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null }); | ||
@@ -236,3 +237,3 @@ try { | ||
describe('.readFile()', () => { | ||
test('can read file contents', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('can read file contents', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { fs } = setup({ folder: { file: 'test' }, 'empty-folder': null }); | ||
@@ -242,3 +243,3 @@ const data = yield fs.promises.readFile('/folder/file'); | ||
})); | ||
test('can read file by file handle', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('can read file by file handle', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { fs } = setup({ folder: { file: 'test' }, 'empty-folder': null }); | ||
@@ -250,3 +251,3 @@ const handle = yield fs.promises.open('/folder/file'); | ||
})); | ||
test('can read file by file descriptor', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('can read file by file descriptor', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { fs } = setup({ folder: { file: 'test' }, 'empty-folder': null }); | ||
@@ -262,3 +263,3 @@ const fd = yield new Promise(resolve => { | ||
})); | ||
test('cannot read from closed file descriptor', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('cannot read from closed file descriptor', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { fs } = setup({ folder: { file: 'test' }, 'empty-folder': null }); | ||
@@ -285,3 +286,3 @@ const fd = yield new Promise(resolve => { | ||
describe('.truncate()', () => { | ||
test('can truncate a file', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('can truncate a file', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null }); | ||
@@ -296,3 +297,3 @@ const res = yield new Promise((resolve, reject) => { | ||
describe('.ftruncate()', () => { | ||
test('can truncate a file', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('can truncate a file', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null }); | ||
@@ -308,3 +309,3 @@ const handle = yield fs.promises.open('/folder/file'); | ||
describe('.readdir()', () => { | ||
test('can read directory contents as strings', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('can read directory contents as strings', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' }); | ||
@@ -317,3 +318,3 @@ const res = (yield fs.promises.readdir('/')); | ||
})); | ||
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', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
var _a, _b, _c, _d; | ||
@@ -332,3 +333,3 @@ const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' }); | ||
describe('.appendFile()', () => { | ||
test('can create a file', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('can create a file', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { fs, mfs } = setup({}); | ||
@@ -338,3 +339,3 @@ yield fs.promises.appendFile('/test.txt', 'a'); | ||
})); | ||
test('can append to a file', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('can append to a file', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { fs, mfs } = setup({}); | ||
@@ -345,3 +346,3 @@ yield fs.promises.appendFile('/test.txt', 'a'); | ||
})); | ||
test('can append to a file - 2', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('can append to a file - 2', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { fs, mfs } = setup({ file: '123' }); | ||
@@ -351,3 +352,3 @@ yield fs.promises.appendFile('file', 'x'); | ||
})); | ||
test('can append to a file - 2', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('can append to a file - 2', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { fs, mfs } = setup({ file: '123' }); | ||
@@ -360,3 +361,3 @@ yield fs.promises.writeFile('cool.txt', 'worlds'); | ||
describe('.write()', () => { | ||
test('can write to a file', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('can write to a file', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { fs, mfs } = setup({}); | ||
@@ -381,3 +382,3 @@ const fd = yield new Promise((resolve, reject) => fs.open('/test.txt', 'w', (err, fd) => { | ||
})); | ||
test('can write to a file twice sequentially', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('can write to a file twice sequentially', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { fs, mfs } = setup({}); | ||
@@ -414,3 +415,3 @@ const fd = yield new Promise((resolve, reject) => fs.open('/test.txt', 'w', (err, fd) => { | ||
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', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { fs, mfs } = setup({}); | ||
@@ -437,5 +438,5 @@ const fd = yield new Promise((resolve, reject) => fs.open('/test.txt', 'w', (err, fd) => { | ||
describe('.exists()', () => { | ||
test('can works for folders and files', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('can works for folders and files', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
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 = (path) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
return new Promise(resolve => { | ||
@@ -457,15 +458,15 @@ fs.exists(path, exists => resolve(exists)); | ||
describe('files', () => { | ||
test('succeeds on file existence check', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('succeeds on file existence check', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
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* () { | ||
test('succeeds on file "read" check', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
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* () { | ||
test('succeeds on file "write" check, on writable file system', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
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* () { | ||
test('fails on file "write" check, on read-only file system', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' }, 'read'); | ||
@@ -480,3 +481,3 @@ try { | ||
})); | ||
test('fails on file "execute" check', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('fails on file "execute" check', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' }); | ||
@@ -493,15 +494,15 @@ try { | ||
describe('directories', () => { | ||
test('succeeds on folder existence check', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('succeeds on folder existence check', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
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* () { | ||
test('succeeds on folder "read" check', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
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* () { | ||
test('succeeds on folder "write" check, on writable file system', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
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* () { | ||
test('fails on folder "write" check, on read-only file system', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' }, 'read'); | ||
@@ -516,3 +517,3 @@ try { | ||
})); | ||
test('fails on folder "execute" check', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('fails on folder "execute" check', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' }); | ||
@@ -530,3 +531,3 @@ try { | ||
describe('.rename()', () => { | ||
test('can rename a file', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('can rename a file', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' }); | ||
@@ -542,3 +543,3 @@ yield fs.promises.rename('/folder/file', '/folder/file2'); | ||
describe('.stat()', () => { | ||
test('can stat a file', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('can stat a file', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' }); | ||
@@ -548,3 +549,3 @@ const stats = yield fs.promises.stat('/folder/file'); | ||
})); | ||
test('throws "ENOENT" when path is not found', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('throws "ENOENT" when path is not found', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { fs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' }); | ||
@@ -554,3 +555,3 @@ const [, error] = yield (0, thingies_1.of)(fs.promises.stat('/folder/repo/.git')); | ||
})); | ||
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', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { fs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' }); | ||
@@ -560,3 +561,3 @@ const [, error] = yield (0, thingies_1.of)(fs.promises.stat('/folder/file/repo/.git')); | ||
})); | ||
test('can retrieve file size', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('can retrieve file size', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' }); | ||
@@ -566,3 +567,3 @@ const stats = yield fs.promises.stat('/folder/file'); | ||
})); | ||
test('can stat a folder', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('can stat a folder', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' }); | ||
@@ -573,3 +574,3 @@ const stats = yield fs.promises.stat('/folder'); | ||
})); | ||
test('throws on non-existing path', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('throws on non-existing path', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' }); | ||
@@ -586,3 +587,3 @@ try { | ||
describe('.lstat()', () => { | ||
test('can stat a file', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('can stat a file', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' }); | ||
@@ -592,3 +593,3 @@ const stats = yield fs.promises.lstat('/folder/file'); | ||
})); | ||
test('can retrieve file size', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('can retrieve file size', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' }); | ||
@@ -598,3 +599,3 @@ const stats = yield fs.promises.lstat('/folder/file'); | ||
})); | ||
test('can stat a folder', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('can stat a folder', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' }); | ||
@@ -605,3 +606,3 @@ const stats = yield fs.promises.lstat('/folder'); | ||
})); | ||
test('throws on non-existing path', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('throws on non-existing path', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { fs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' }); | ||
@@ -618,3 +619,3 @@ try { | ||
describe('.fstat()', () => { | ||
test('can stat a file', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('can stat a file', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { fs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' }); | ||
@@ -634,3 +635,3 @@ const handle = yield fs.promises.open('/folder/file', 'r'); | ||
describe('.realpath()', () => { | ||
test('returns file path', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('returns file path', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { fs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' }); | ||
@@ -642,3 +643,3 @@ const path = yield fs.promises.realpath('folder/file'); | ||
describe('.realpathSync()', () => { | ||
test('returns file path', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('returns file path', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { fs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' }); | ||
@@ -650,3 +651,3 @@ const path = fs.realpathSync('folder/file'); | ||
describe('.copyFile()', () => { | ||
test('can copy a file', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('can copy a file', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' }); | ||
@@ -663,3 +664,3 @@ yield fs.promises.copyFile('/folder/file', '/folder/file2'); | ||
describe('.writeFile()', () => { | ||
test('can create a new file', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('can create a new file', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' }); | ||
@@ -682,5 +683,17 @@ const res = yield new Promise((resolve, reject) => { | ||
})); | ||
test('throws "EEXIST", if file already exists and O_EXCL flag set', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { fs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' }); | ||
const [, err] = yield (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', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { fs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' }); | ||
const [, err] = yield (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', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { fs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' }); | ||
@@ -700,3 +713,3 @@ const handle = yield fs.promises.open('/folder/file', 'r'); | ||
})); | ||
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', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { fs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' }); | ||
@@ -719,3 +732,3 @@ const handle = yield fs.promises.open('/folder/file', 'r'); | ||
describe('.createWriteStream()', () => { | ||
test('can use stream to write to a new file', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('can use stream to write to a new file', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' }); | ||
@@ -736,3 +749,3 @@ const stream = fs.createWriteStream('/folder/file2'); | ||
})); | ||
test('can use stream to write to a new file using strings', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('can use stream to write to a new file using strings', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' }); | ||
@@ -753,3 +766,3 @@ const stream = fs.createWriteStream('/folder/file2'); | ||
})); | ||
test('can use stream to overwrite existing file', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('can use stream to overwrite existing file', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' }); | ||
@@ -768,3 +781,3 @@ const stream = fs.createWriteStream('/folder/file'); | ||
})); | ||
test('can write by file descriptor', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('can write by file descriptor', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' }); | ||
@@ -783,3 +796,3 @@ const handle = yield fs.promises.open('/folder/file', 'a'); | ||
})); | ||
test('closes file once stream ends', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('closes file once stream ends', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { fs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' }); | ||
@@ -789,3 +802,3 @@ const handle = yield fs.promises.open('/folder/file', 'a'); | ||
stream.write(Buffer.from('BC')); | ||
const stat = () => __awaiter(void 0, void 0, void 0, function* () { | ||
const stat = () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
return yield new Promise((resolve, reject) => fs.fstat(handle.fd, (err, stats) => { | ||
@@ -800,3 +813,3 @@ if (err) | ||
stream.end(); | ||
yield (0, thingies_1.until)(() => __awaiter(void 0, void 0, void 0, function* () { | ||
yield (0, thingies_1.until)(() => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const [, error] = yield (0, thingies_1.of)(stat()); | ||
@@ -808,3 +821,3 @@ return !!error; | ||
})); | ||
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', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { fs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' }); | ||
@@ -814,3 +827,3 @@ const handle = yield fs.promises.open('/folder/file', 'a'); | ||
stream.write(Buffer.from('BC')); | ||
const stat = () => __awaiter(void 0, void 0, void 0, function* () { | ||
const stat = () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
return yield new Promise((resolve, reject) => fs.fstat(handle.fd, (err, stats) => { | ||
@@ -828,3 +841,3 @@ if (err) | ||
})); | ||
test('can use stream to add to existing file', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('can use stream to add to existing file', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' }); | ||
@@ -843,3 +856,3 @@ const stream = fs.createWriteStream('/folder/file', { flags: 'a' }); | ||
})); | ||
test('can use stream to add to existing file at specified offset', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('can use stream to add to existing file at specified offset', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' }); | ||
@@ -858,3 +871,3 @@ const stream = fs.createWriteStream('/folder/file', { flags: 'a', start: 1 }); | ||
})); | ||
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', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { fs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' }); | ||
@@ -870,3 +883,3 @@ try { | ||
})); | ||
test('throws if "start" option is negative', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('throws if "start" option is negative', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { fs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' }); | ||
@@ -884,3 +897,3 @@ try { | ||
describe('.createReadStream()', () => { | ||
test('can pipe fs.ReadStream to fs.WriteStream', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('can pipe fs.ReadStream to fs.WriteStream', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' }); | ||
@@ -898,3 +911,3 @@ const readStream = fs.createReadStream('/folder/file'); | ||
})); | ||
test('emits "open" event', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('emits "open" event', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { fs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' }); | ||
@@ -905,3 +918,3 @@ const readStream = fs.createReadStream('/folder/file'); | ||
})); | ||
test('emits "ready" event', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('emits "ready" event', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { fs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' }); | ||
@@ -911,3 +924,3 @@ const readStream = fs.createReadStream('/folder/file'); | ||
})); | ||
test('emits "close" event', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('emits "close" event', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { fs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' }); | ||
@@ -919,3 +932,3 @@ const readStream = fs.createReadStream('/folder/file', { emitClose: true }); | ||
})); | ||
test('can write to already open file', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('can write to already open file', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' }); | ||
@@ -934,3 +947,3 @@ const handle = yield fs.promises.open('/folder/file'); | ||
})); | ||
test('can read a specified slice of a file', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('can read a specified slice of a file', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' }); | ||
@@ -950,1 +963,2 @@ const readStream = fs.createReadStream('/folder/file', { start: 1, end: 2 }); | ||
}); | ||
//# 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 }); | ||
exports.FsaNodeCore = void 0; | ||
const tslib_1 = require("tslib"); | ||
const util_1 = require("../node/util"); | ||
@@ -17,2 +9,3 @@ const util_2 = require("./util"); | ||
const FsaNodeFsOpenFile_1 = require("./FsaNodeFsOpenFile"); | ||
const util = require("../node/util"); | ||
class FsaNodeCore { | ||
@@ -51,3 +44,3 @@ constructor(root, syncAdapter) { | ||
getDir(path, create, funcName) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
let curr = yield this.root; | ||
@@ -75,3 +68,3 @@ const options = { create }; | ||
getFile(path, name, funcName, create) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const dir = yield this.getDir(path, false, funcName); | ||
@@ -82,5 +75,7 @@ const file = yield dir.getFileHandle(name, { create }); | ||
} | ||
getFileOrDir(path, name, funcName, create) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
getFileOrDir(path, name, funcName) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const dir = yield this.getDir(path, false, funcName); | ||
if (!name) | ||
return dir; | ||
try { | ||
@@ -124,8 +119,8 @@ const file = yield dir.getFileHandle(name); | ||
getFileByFdAsync(fd, funcName) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
return this.getFileByFd(fd, funcName); | ||
}); | ||
} | ||
__getFileById(id, funcName, create) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
__getFileById(id, funcName) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
if (typeof id === 'number') | ||
@@ -135,7 +130,7 @@ return (yield this.getFileByFd(id, funcName)).file; | ||
const [folder, name] = (0, util_2.pathToLocation)(filename); | ||
return yield this.getFile(folder, name, funcName, create); | ||
return yield this.getFile(folder, name, funcName); | ||
}); | ||
} | ||
getFileByIdOrCreate(id, funcName) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
if (typeof id === 'number') | ||
@@ -150,7 +145,41 @@ return (yield this.getFileByFd(id, funcName)).file; | ||
__open(filename, flags, mode) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const [folder, name] = (0, util_2.pathToLocation)(filename); | ||
const createIfMissing = !!(flags & 64 /* FLAG.O_CREAT */); | ||
const fsaFile = yield this.getFile(folder, name, 'open', createIfMissing); | ||
return this.__open2(fsaFile, filename, flags, mode); | ||
const throwIfExists = !!(flags & 128 /* FLAG.O_EXCL */); | ||
if (throwIfExists) { | ||
try { | ||
yield 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); | ||
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; | ||
} | ||
}); | ||
@@ -164,2 +193,11 @@ } | ||
} | ||
__close(fd) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const openFile = yield this.getFileByFdAsync(fd, 'close'); | ||
yield openFile.close(); | ||
const deleted = this.fds.delete(fd); | ||
if (deleted) | ||
this.releasedFds.push(fd); | ||
}); | ||
} | ||
getFileName(id) { | ||
@@ -177,1 +215,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,3 +65,3 @@ this.read = (fd, buffer, offset, length, position, callback) => { | ||
} | ||
(() => __awaiter(this, void 0, void 0, function* () { | ||
(() => tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const openFile = yield this.getFileByFd(fd, 'read'); | ||
@@ -98,16 +79,30 @@ const file = yield openFile.file.getFile(); | ||
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); | ||
}); | ||
(() => tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
let fd = typeof id === 'number' ? id : -1; | ||
const originalFd = fd; | ||
try { | ||
if (fd === -1) { | ||
const filename = util.pathToFilename(id); | ||
fd = (yield this.__open(filename, flagsNum, 0)).fd; | ||
} | ||
const handle = yield this.__getFileById(fd, 'readFile'); | ||
const file = yield handle.getFile(); | ||
const buffer = Buffer.from(yield file.arrayBuffer()); | ||
return util.bufferToEncoding(buffer, opts.encoding); | ||
} | ||
finally { | ||
try { | ||
const idWasFd = typeof originalFd === 'number' && originalFd >= 0; | ||
if (idWasFd) | ||
yield 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* () { | ||
(() => tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const openFile = yield this.getFileByFd(fd, 'write'); | ||
@@ -131,3 +126,3 @@ const data = buf.subarray(offset, offset + length); | ||
util.validateCallback(callback); | ||
(() => __awaiter(this, void 0, void 0, function* () { | ||
(() => tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const openFile = yield this.getFileByFd(fd, 'writev'); | ||
@@ -157,8 +152,23 @@ const length = buffers.length; | ||
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(); | ||
(() => tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
let fd = typeof id === 'number' ? id : -1; | ||
const originalFd = fd; | ||
try { | ||
if (fd === -1) { | ||
const filename = util.pathToFilename(id); | ||
fd = (yield this.__open(filename, flagsNum, modeNum)).fd; | ||
} | ||
const file = yield this.__getFileById(fd, 'writeFile'); | ||
const writable = yield file.createWritable({ keepExistingData: false }); | ||
yield writable.write(buf); | ||
yield writable.close(); | ||
} | ||
finally { | ||
try { | ||
const idWasFd = typeof originalFd === 'number' && originalFd >= 0; | ||
if (idWasFd) | ||
yield this.__close(originalFd); | ||
} | ||
catch (_a) { } | ||
} | ||
}))().then(() => cb(null), error => cb(error)); | ||
@@ -182,3 +192,3 @@ }; | ||
const [newFolder, newName] = (0, util_1.pathToLocation)(destFilename); | ||
(() => __awaiter(this, void 0, void 0, function* () { | ||
(() => tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const oldFile = yield this.getFile(oldFolder, oldName, 'copyFile'); | ||
@@ -229,3 +239,3 @@ const newDir = yield this.getDir(newFolder, false, 'copyFile'); | ||
const [folder, name] = (0, util_1.pathToLocation)(filename); | ||
(() => __awaiter(this, void 0, void 0, function* () { | ||
(() => tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const handle = yield this.getFileOrDir(folder, name, 'stat'); | ||
@@ -238,3 +248,3 @@ return yield this.getHandleStats(bigint, handle); | ||
const [{ bigint = false, throwIfNoEntry = true }, callback] = optHelpers.getStatOptsAndCb(a, b); | ||
(() => __awaiter(this, void 0, void 0, function* () { | ||
(() => tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const openFile = yield this.getFileByFd(fd, 'fstat'); | ||
@@ -253,3 +263,3 @@ return yield this.getHandleStats(bigint, openFile.file); | ||
const [newFolder, newName] = (0, util_1.pathToLocation)(newPathFilename); | ||
(() => __awaiter(this, void 0, void 0, function* () { | ||
(() => tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const oldFile = yield this.getFile(oldFolder, oldName, 'rename'); | ||
@@ -284,3 +294,3 @@ const newDir = yield this.getDir(newFolder, false, 'rename'); | ||
const [folder, name] = (0, util_1.pathToLocation)(filename); | ||
(() => __awaiter(this, void 0, void 0, function* () { | ||
(() => tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const node = folder.length || name ? yield this.getFileOrDir(folder, name, 'access') : yield this.root; | ||
@@ -324,3 +334,3 @@ const checkIfCanExecute = mode & 1 /* AMODE.X_OK */; | ||
this.getFileByIdOrCreate(id, 'appendFile') | ||
.then(file => (() => __awaiter(this, void 0, void 0, function* () { | ||
.then(file => (() => tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const blob = yield file.getFile(); | ||
@@ -344,3 +354,3 @@ const writable = yield file.createWritable({ keepExistingData: true }); | ||
this.getDir(folder, false, 'readdir') | ||
.then(dir => (() => __awaiter(this, void 0, void 0, function* () { | ||
.then(dir => (() => tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
var _a, e_1, _b, _c, _d, e_2, _e, _f; | ||
@@ -350,13 +360,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 = yield _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); | ||
} | ||
@@ -384,12 +389,7 @@ } | ||
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 = yield _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); | ||
} | ||
@@ -610,4 +610,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; | ||
/** | ||
@@ -621,2 +625,4 @@ * @todo Watchers could be implemented in the future on top of `FileSystemObserver`, | ||
this.watch = notSupported; | ||
this.symlink = notSupported; | ||
this.link = notSupported; | ||
// --------------------------------------------------------- FsSynchronousApi | ||
@@ -794,2 +800,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; | ||
@@ -805,2 +819,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; | ||
@@ -824,3 +843,3 @@ this.linkSync = notSupported; | ||
getHandleStats(bigint, handle) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
let size = 0; | ||
@@ -837,16 +856,11 @@ if (handle.kind === 'file') { | ||
rmAll(callback) { | ||
(() => __awaiter(this, void 0, void 0, function* () { | ||
(() => tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
var _a, e_3, _b, _c; | ||
const root = yield 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 = yield _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; | ||
yield root.removeEntry(name, { recursive: true }); | ||
} | ||
@@ -865,1 +879,2 @@ } | ||
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 }); | ||
exports.FsaNodeFsOpenFile = void 0; | ||
const tslib_1 = require("tslib"); | ||
/** | ||
@@ -28,6 +20,6 @@ * Represents an open file. Stores additional metadata about the open file, such | ||
close() { | ||
return __awaiter(this, void 0, void 0, function* () { }); | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { }); | ||
} | ||
write(data, seek) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
if (typeof seek !== 'number') | ||
@@ -48,1 +40,2 @@ seek = this.seek; | ||
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 }); | ||
exports.FsaNodeReadStream = void 0; | ||
const tslib_1 = require("tslib"); | ||
const stream_1 = require("stream"); | ||
@@ -45,4 +37,4 @@ const Defer_1 = require("thingies/es6/Defer"); | ||
__read__() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return yield this.__mutex__(() => __awaiter(this, void 0, void 0, function* () { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
return yield this.__mutex__(() => tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
if (this.__closed__) | ||
@@ -102,1 +94,2 @@ return; | ||
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 }); | ||
exports.FsaNodeWriteStream = void 0; | ||
const tslib_1 = require("tslib"); | ||
const stream_1 = require("stream"); | ||
@@ -57,3 +49,3 @@ const Defer_1 = require("thingies/es6/Defer"); | ||
this.__stream__ = stream.promise; | ||
(() => __awaiter(this, void 0, void 0, function* () { | ||
(() => tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
var _a, _b; | ||
@@ -79,4 +71,4 @@ const fsaHandle = yield handle; | ||
___write___(buffers) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
yield this.__mutex__(() => __awaiter(this, void 0, void 0, function* () { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
yield this.__mutex__(() => tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
if (this.__closed__) | ||
@@ -94,5 +86,5 @@ return; | ||
__close__() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const emitClose = this.options.emitClose; | ||
yield this.__mutex__(() => __awaiter(this, void 0, void 0, function* () { | ||
yield this.__mutex__(() => tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
if (this.__closed__ && emitClose) { | ||
@@ -166,1 +158,2 @@ process.nextTick(() => this.emit('close')); | ||
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 }); | ||
exports.testDirectoryIsWritable = exports.pathToLocation = void 0; | ||
const tslib_1 = require("tslib"); | ||
const pathToLocation = (path) => { | ||
if (path[0] === "/" /* FsaToNodeConstants.Separator */) | ||
path = path.slice(1); | ||
if (path[path.length - 1] === "/" /* FsaToNodeConstants.Separator */) | ||
path = path.slice(0, -1); | ||
const lastSlashIndex = path.lastIndexOf("/" /* FsaToNodeConstants.Separator */); | ||
@@ -24,3 +18,3 @@ if (lastSlashIndex === -1) | ||
exports.pathToLocation = pathToLocation; | ||
const testDirectoryIsWritable = (dir) => __awaiter(void 0, void 0, void 0, function* () { | ||
const testDirectoryIsWritable = (dir) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const testFileName = '__memfs_writable_test_file_' + Math.random().toString(36).slice(2) + Date.now(); | ||
@@ -42,1 +36,2 @@ try { | ||
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 }); | ||
exports.FsaNodeSyncAdapterWorker = void 0; | ||
const tslib_1 = require("tslib"); | ||
const Defer_1 = require("thingies/es6/Defer"); | ||
@@ -19,3 +11,3 @@ const SyncMessenger_1 = require("./SyncMessenger"); | ||
static start(url, dir) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const worker = new Worker(url); | ||
@@ -74,1 +66,2 @@ const future = new Defer_1.Defer(); | ||
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 }); | ||
exports.FsaNodeSyncWorker = void 0; | ||
const tslib_1 = require("tslib"); | ||
const SyncMessenger_1 = require("./SyncMessenger"); | ||
@@ -33,3 +25,3 @@ const FsaNodeFs_1 = require("../FsaNodeFs"); | ||
}; | ||
this.onRequest = (request) => __awaiter(this, void 0, void 0, function* () { | ||
this.onRequest = (request) => tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
try { | ||
@@ -58,3 +50,3 @@ const message = json_1.decoder.decode(request); | ||
this.handlers = { | ||
stat: (location) => __awaiter(this, void 0, void 0, function* () { | ||
stat: (location) => tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const handle = yield this.getFileOrDir(location[0], location[1], 'statSync'); | ||
@@ -65,6 +57,6 @@ return { | ||
}), | ||
access: ([filename, mode]) => __awaiter(this, void 0, void 0, function* () { | ||
access: ([filename, mode]) => tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
yield this.fs.promises.access(filename, mode); | ||
}), | ||
readFile: ([filename, opts]) => __awaiter(this, void 0, void 0, function* () { | ||
readFile: ([filename, opts]) => tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const buf = (yield this.fs.promises.readFile(filename, Object.assign(Object.assign({}, opts), { encoding: 'buffer' }))); | ||
@@ -74,33 +66,33 @@ const uint8 = new Uint8Array(buf, buf.byteOffset, buf.byteLength); | ||
}), | ||
writeFile: ([filename, data, opts]) => __awaiter(this, void 0, void 0, function* () { | ||
writeFile: ([filename, data, opts]) => tslib_1.__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* () { | ||
appendFile: ([filename, data, opts]) => tslib_1.__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* () { | ||
copy: ([src, dst, flags]) => tslib_1.__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* () { | ||
move: ([src, dst]) => tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
yield this.fs.promises.rename(src, dst); | ||
}), | ||
rmdir: ([filename, options]) => __awaiter(this, void 0, void 0, function* () { | ||
rmdir: ([filename, options]) => tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
yield this.fs.promises.rmdir(filename, options); | ||
}), | ||
rm: ([filename, options]) => __awaiter(this, void 0, void 0, function* () { | ||
rm: ([filename, options]) => tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
yield this.fs.promises.rm(filename, options); | ||
}), | ||
mkdir: ([filename, options]) => __awaiter(this, void 0, void 0, function* () { | ||
mkdir: ([filename, options]) => tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
return yield this.fs.promises.mkdir(filename, options); | ||
}), | ||
mkdtemp: ([filename]) => __awaiter(this, void 0, void 0, function* () { | ||
mkdtemp: ([filename]) => tslib_1.__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* () { | ||
trunc: ([filename, len]) => tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
yield this.fs.promises.truncate(filename, len); | ||
}), | ||
unlink: ([filename]) => __awaiter(this, void 0, void 0, function* () { | ||
unlink: ([filename]) => tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
yield this.fs.promises.unlink(filename); | ||
}), | ||
readdir: ([filename]) => __awaiter(this, void 0, void 0, function* () { | ||
readdir: ([filename]) => tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const list = (yield this.fs.promises.readdir(filename, { withFileTypes: true, encoding: 'utf8' })); | ||
@@ -113,3 +105,3 @@ const res = list.map(entry => ({ | ||
}), | ||
read: ([filename, position, length]) => __awaiter(this, void 0, void 0, function* () { | ||
read: ([filename, position, length]) => tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
let uint8 = new Uint8Array(length); | ||
@@ -128,3 +120,3 @@ const handle = yield this.fs.promises.open(filename, 'r'); | ||
}), | ||
write: ([filename, data, position]) => __awaiter(this, void 0, void 0, function* () { | ||
write: ([filename, data, position]) => tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const handle = yield this.fs.promises.open(filename, 'a'); | ||
@@ -134,3 +126,3 @@ const { bytesWritten } = yield handle.write(data, 0, data.length, position || undefined); | ||
}), | ||
open: ([filename, flags, mode]) => __awaiter(this, void 0, void 0, function* () { | ||
open: ([filename, flags, mode]) => tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const handle = yield this.fs.promises.open(filename, flags, mode); | ||
@@ -153,3 +145,3 @@ const file = yield this.fs.__getFileById(handle.fd); | ||
getDir(path, create, funcName) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
let curr = this.root; | ||
@@ -171,3 +163,3 @@ const options = { create }; | ||
getFile(path, name, funcName, create) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const dir = yield this.getDir(path, false, funcName); | ||
@@ -179,3 +171,3 @@ const file = yield dir.getFileHandle(name, { create }); | ||
getFileOrDir(path, name, funcName, create) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const dir = yield this.getDir(path, false, funcName); | ||
@@ -201,1 +193,2 @@ try { | ||
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 }); | ||
exports.SyncMessenger = void 0; | ||
const tslib_1 = require("tslib"); | ||
/** | ||
@@ -61,3 +53,3 @@ * @param condition Condition to wait for, when true, the function returns. | ||
const headerSize = this.headerSize; | ||
(() => __awaiter(this, void 0, void 0, function* () { | ||
(() => tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
try { | ||
@@ -82,1 +74,2 @@ const int32 = this.int32; | ||
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 |
@@ -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') | ||
@@ -53,1 +54,2 @@ fs[method] = vol[method].bind(vol); | ||
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("../.."); | ||
@@ -34,3 +19,3 @@ const NodeFileSystemDirectoryHandle_1 = require("../NodeFileSystemDirectoryHandle"); | ||
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', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { dir } = setup(); | ||
@@ -40,3 +25,3 @@ const keys = dir.keys(); | ||
})); | ||
test('returns a folder', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('returns a folder', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
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 = yield _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); | ||
} | ||
@@ -68,3 +48,3 @@ } | ||
})); | ||
test('returns two folders', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('returns two folders', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
var _g, e_2, _h, _j; | ||
@@ -77,12 +57,7 @@ const { dir } = setup({ | ||
try { | ||
for (var _k = true, _l = __asyncValues(dir.keys()), _m; _m = yield _l.next(), _g = _m.done, !_g;) { | ||
for (var _k = true, _l = tslib_1.__asyncValues(dir.keys()), _m; _m = yield _l.next(), _g = _m.done, !_g; _k = true) { | ||
_j = _m.value; | ||
_k = false; | ||
try { | ||
const key = _j; | ||
list.push(key); | ||
} | ||
finally { | ||
_k = true; | ||
} | ||
const key = _j; | ||
list.push(key); | ||
} | ||
@@ -99,3 +74,3 @@ } | ||
})); | ||
test('returns a file', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('returns a file', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
var _o, e_3, _p, _q; | ||
@@ -107,12 +82,7 @@ const { dir } = setup({ | ||
try { | ||
for (var _r = true, _s = __asyncValues(dir.keys()), _t; _t = yield _s.next(), _o = _t.done, !_o;) { | ||
for (var _r = true, _s = tslib_1.__asyncValues(dir.keys()), _t; _t = yield _s.next(), _o = _t.done, !_o; _r = true) { | ||
_q = _t.value; | ||
_r = false; | ||
try { | ||
const key = _q; | ||
list.push(key); | ||
} | ||
finally { | ||
_r = true; | ||
} | ||
const key = _q; | ||
list.push(key); | ||
} | ||
@@ -131,3 +101,3 @@ } | ||
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', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { dir } = setup(); | ||
@@ -137,19 +107,14 @@ const keys = dir.entries(); | ||
})); | ||
test('returns a folder', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('returns a folder', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
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 = yield _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'); | ||
} | ||
@@ -165,3 +130,3 @@ } | ||
})); | ||
test('returns a file', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('returns a file', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
var _g, e_5, _h, _j; | ||
@@ -172,15 +137,10 @@ const { dir } = setup({ | ||
try { | ||
for (var _k = true, _l = __asyncValues(dir.entries()), _m; _m = yield _l.next(), _g = _m.done, !_g;) { | ||
for (var _k = true, _l = tslib_1.__asyncValues(dir.entries()), _m; _m = yield _l.next(), _g = _m.done, !_g; _k = true) { | ||
_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; | ||
} | ||
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'); | ||
} | ||
@@ -196,3 +156,3 @@ } | ||
})); | ||
test('returns two entries', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('returns two entries', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
var _o, e_6, _p, _q; | ||
@@ -205,12 +165,7 @@ const { dir } = setup({ | ||
try { | ||
for (var _r = true, _s = __asyncValues(dir.entries()), _t; _t = yield _s.next(), _o = _t.done, !_o;) { | ||
for (var _r = true, _s = tslib_1.__asyncValues(dir.entries()), _t; _t = yield _s.next(), _o = _t.done, !_o; _r = true) { | ||
_q = _t.value; | ||
_r = false; | ||
try { | ||
const entry = _q; | ||
handles.push(entry[1]); | ||
} | ||
finally { | ||
_r = true; | ||
} | ||
const entry = _q; | ||
handles.push(entry[1]); | ||
} | ||
@@ -231,3 +186,3 @@ } | ||
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', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { dir } = setup(); | ||
@@ -237,18 +192,13 @@ const values = dir.values(); | ||
})); | ||
test('returns a folder', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('returns a folder', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
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 = yield _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'); | ||
} | ||
@@ -264,3 +214,3 @@ } | ||
})); | ||
test('returns a file', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('returns a file', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
var _g, e_8, _h, _j; | ||
@@ -271,14 +221,9 @@ const { dir } = setup({ | ||
try { | ||
for (var _k = true, _l = __asyncValues(dir.values()), _m; _m = yield _l.next(), _g = _m.done, !_g;) { | ||
for (var _k = true, _l = tslib_1.__asyncValues(dir.values()), _m; _m = yield _l.next(), _g = _m.done, !_g; _k = true) { | ||
_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; | ||
} | ||
const file = _j; | ||
expect(file).toBeInstanceOf(NodeFileSystemFileHandle_1.NodeFileSystemFileHandle); | ||
expect(file.kind).toBe('file'); | ||
expect(file.name).toBe('file.txt'); | ||
} | ||
@@ -294,3 +239,3 @@ } | ||
})); | ||
test('returns two entries', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('returns two entries', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
var _o, e_9, _p, _q; | ||
@@ -303,12 +248,7 @@ const { dir } = setup({ | ||
try { | ||
for (var _r = true, _s = __asyncValues(dir.values()), _t; _t = yield _s.next(), _o = _t.done, !_o;) { | ||
for (var _r = true, _s = tslib_1.__asyncValues(dir.values()), _t; _t = yield _s.next(), _o = _t.done, !_o; _r = true) { | ||
_q = _t.value; | ||
_r = false; | ||
try { | ||
const entry = _q; | ||
handles.push(entry); | ||
} | ||
finally { | ||
_r = true; | ||
} | ||
const entry = _q; | ||
handles.push(entry); | ||
} | ||
@@ -329,3 +269,3 @@ } | ||
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', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { dir } = setup({ a: null }); | ||
@@ -342,3 +282,3 @@ try { | ||
})); | ||
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', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { dir } = setup({ file: 'contents' }); | ||
@@ -355,3 +295,3 @@ try { | ||
})); | ||
test('throws if not in "readwrite" mode and attempting to create a directory', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('throws if not in "readwrite" mode and attempting to create a directory', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const fs = (0, __1.memfs)({}, '/'); | ||
@@ -387,3 +327,3 @@ const dir = new NodeFileSystemDirectoryHandle_1.NodeFileSystemDirectoryHandle(fs, '/', { mode: 'read' }); | ||
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}"`, () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { dir } = setup({ file: 'contents' }); | ||
@@ -400,3 +340,3 @@ try { | ||
} | ||
test('can retrieve a child directory', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('can retrieve a child directory', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { dir } = setup({ file: 'contents', subdir: null }); | ||
@@ -408,3 +348,3 @@ const subdir = yield dir.getDirectoryHandle('subdir'); | ||
})); | ||
test('can create a sub-directory', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('can create a sub-directory', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { dir, fs } = setup({}); | ||
@@ -421,3 +361,3 @@ expect(fs.existsSync('/subdir')).toBe(false); | ||
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', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { dir } = setup({ a: null }); | ||
@@ -434,3 +374,3 @@ try { | ||
})); | ||
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', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { dir } = setup({ directory: null }); | ||
@@ -447,3 +387,3 @@ try { | ||
})); | ||
test('throws if not in "readwrite" mode and attempting to create a file', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('throws if not in "readwrite" mode and attempting to create a file', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const fs = (0, __1.memfs)({}, '/'); | ||
@@ -480,3 +420,3 @@ const dir = new NodeFileSystemDirectoryHandle_1.NodeFileSystemDirectoryHandle(fs, '/', { mode: 'read' }); | ||
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}"`, () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { dir } = setup({ file: 'contents' }); | ||
@@ -493,3 +433,3 @@ try { | ||
} | ||
test('can retrieve a child file', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('can retrieve a child file', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { dir } = setup({ file: 'contents', subdir: null }); | ||
@@ -501,3 +441,3 @@ const subdir = yield dir.getFileHandle('file'); | ||
})); | ||
test('can create a file', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('can create a file', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { dir, fs } = setup({}); | ||
@@ -514,3 +454,3 @@ expect(fs.existsSync('/text.txt')).toBe(false); | ||
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', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { dir } = setup({ a: null }); | ||
@@ -527,3 +467,3 @@ try { | ||
})); | ||
test('throws if not in "readwrite" mode and attempting to remove a file', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('throws if not in "readwrite" mode and attempting to remove a file', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const fs = (0, __1.memfs)({ a: 'b' }, '/'); | ||
@@ -541,3 +481,3 @@ const dir = new NodeFileSystemDirectoryHandle_1.NodeFileSystemDirectoryHandle(fs, '/', { mode: 'read' }); | ||
})); | ||
test('throws if not in "readwrite" mode and attempting to remove a folder', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('throws if not in "readwrite" mode and attempting to remove a folder', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const fs = (0, __1.memfs)({ a: null }, '/'); | ||
@@ -574,3 +514,3 @@ const dir = new NodeFileSystemDirectoryHandle_1.NodeFileSystemDirectoryHandle(fs, '/', { mode: 'read' }); | ||
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}"`, () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { dir } = setup({ file: 'contents' }); | ||
@@ -587,3 +527,3 @@ try { | ||
} | ||
test('can delete a file', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('can delete a file', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { dir, fs } = setup({ file: 'contents', subdir: null }); | ||
@@ -595,3 +535,3 @@ expect(fs.statSync('/file').isFile()).toBe(true); | ||
})); | ||
test('can delete a folder', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('can delete a folder', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { dir, fs } = setup({ dir: null }); | ||
@@ -603,3 +543,3 @@ expect(fs.statSync('/dir').isDirectory()).toBe(true); | ||
})); | ||
test('throws "InvalidModificationError" DOMException if directory has contents', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('throws "InvalidModificationError" DOMException if directory has contents', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { dir, fs } = setup({ | ||
@@ -621,3 +561,3 @@ 'dir/file': 'contents', | ||
})); | ||
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', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { dir, fs } = setup({ | ||
@@ -633,3 +573,3 @@ 'dir/file': 'contents', | ||
describe('.resolve()', () => { | ||
test('return empty array for itself', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('return empty array for itself', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { dir } = setup({}); | ||
@@ -639,3 +579,3 @@ const res = yield dir.resolve(dir); | ||
})); | ||
test('can resolve one level deep child', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('can resolve one level deep child', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { dir } = setup({ | ||
@@ -648,3 +588,3 @@ file: 'contents', | ||
})); | ||
test('can resolve two level deep child', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('can resolve two level deep child', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { dir } = setup({ | ||
@@ -660,3 +600,3 @@ 'dir/file': 'contents', | ||
})); | ||
test('returns "null" if not a descendant', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('returns "null" if not a descendant', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { dir } = setup({ | ||
@@ -671,1 +611,2 @@ 'dir/file': 'contents', | ||
}); | ||
//# 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 }); | ||
const tslib_1 = require("tslib"); | ||
const __1 = require("../.."); | ||
@@ -22,3 +14,3 @@ const NodeFileSystemDirectoryHandle_1 = require("../NodeFileSystemDirectoryHandle"); | ||
describe('.getFile()', () => { | ||
test('can read file contents', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('can read file contents', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { dir, fs } = setup({ | ||
@@ -38,3 +30,3 @@ 'file.txt': 'Hello, world!', | ||
describe('.createWritable()', () => { | ||
test('throws if not in "readwrite" mode', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('throws if not in "readwrite" mode', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const fs = (0, __1.memfs)({ 'file.txt': 'abc' }, '/'); | ||
@@ -54,3 +46,3 @@ const dir = new NodeFileSystemDirectoryHandle_1.NodeFileSystemDirectoryHandle(fs, '/', { mode: 'read' }); | ||
describe('.truncate()', () => { | ||
test('can truncate file', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('can truncate file', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { dir, fs } = setup({ | ||
@@ -65,3 +57,3 @@ 'file.txt': '012345', | ||
})); | ||
test('can truncate file - 2', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('can truncate file - 2', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { dir, fs } = setup({ | ||
@@ -76,3 +68,3 @@ 'file.txt': '012345', | ||
})); | ||
test('can truncate up', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('can truncate up', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { dir, fs } = setup({ | ||
@@ -88,3 +80,3 @@ 'file.txt': '012345', | ||
})); | ||
test('on up truncation bytes are nulled', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('on up truncation bytes are nulled', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { dir, fs } = setup({ | ||
@@ -101,3 +93,3 @@ 'file.txt': '012345', | ||
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', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { dir, fs } = setup({ | ||
@@ -112,3 +104,3 @@ 'file.txt': 'Hello, world!', | ||
})); | ||
test('writes at file start', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('writes at file start', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { dir, fs } = setup({ | ||
@@ -123,3 +115,3 @@ 'file.txt': '...', | ||
})); | ||
test('can seek and then write', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('can seek and then write', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { dir, fs } = setup({ | ||
@@ -137,3 +129,3 @@ 'file.txt': '...', | ||
})); | ||
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', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { dir, fs } = setup({ | ||
@@ -149,3 +141,3 @@ 'file.txt': '...', | ||
})); | ||
test('does not commit changes if .abort() is called and removes the swap file', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('does not commit changes if .abort() is called and removes the swap file', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { dir, fs } = setup({ | ||
@@ -168,3 +160,3 @@ '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', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { dir, fs } = setup({ | ||
@@ -179,3 +171,3 @@ 'file.txt': '...', | ||
})); | ||
test('can seek and then write', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('can seek and then write', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { dir, fs } = setup({ | ||
@@ -191,3 +183,3 @@ 'file.txt': '...', | ||
})); | ||
test('can seek and then write', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('can seek and then write', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { dir, fs } = setup({ | ||
@@ -206,1 +198,2 @@ 'file.txt': '...', | ||
}); | ||
//# 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 }); | ||
const tslib_1 = require("tslib"); | ||
const __1 = require("../.."); | ||
@@ -26,7 +18,7 @@ const NodeFileSystemDirectoryHandle_1 = require("../NodeFileSystemDirectoryHandle"); | ||
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', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
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', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { dir } = setup({ | ||
@@ -41,3 +33,3 @@ subdir: null, | ||
})); | ||
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', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { dir } = setup({ | ||
@@ -52,1 +44,2 @@ file: 'lala', | ||
}); | ||
//# 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 }); | ||
const tslib_1 = require("tslib"); | ||
const __1 = require("../.."); | ||
@@ -23,3 +15,3 @@ const NodeFileSystemDirectoryHandle_1 = require("../NodeFileSystemDirectoryHandle"); | ||
describe('.close()', () => { | ||
test('can close the file', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('can close the file', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { dir } = setup({ | ||
@@ -36,3 +28,3 @@ 'file.txt': 'Hello, world!', | ||
describe('.flush()', () => { | ||
test('can flush', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('can flush', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { dir } = setup({ | ||
@@ -47,3 +39,3 @@ 'file.txt': 'Hello, world!', | ||
describe('.getSize()', () => { | ||
test('can get file size', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('can get file size', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { dir } = setup({ | ||
@@ -59,3 +51,3 @@ 'file.txt': 'Hello, world!', | ||
describe('.getSize()', () => { | ||
test('can get file size', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('can get file size', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { dir } = setup({ | ||
@@ -71,3 +63,3 @@ 'file.txt': 'Hello, world!', | ||
describe('.read()', () => { | ||
test('can read from beginning', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('can read from beginning', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { dir } = setup({ | ||
@@ -83,3 +75,3 @@ 'file.txt': '0123456789', | ||
})); | ||
test('can read at offset', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('can read at offset', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { dir } = setup({ | ||
@@ -95,3 +87,3 @@ 'file.txt': '0123456789', | ||
})); | ||
test('can read into buffer larger than file', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('can read into buffer larger than file', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { dir } = setup({ | ||
@@ -107,3 +99,3 @@ 'file.txt': '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', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { dir } = setup({ | ||
@@ -127,3 +119,3 @@ 'file.txt': '0123456789', | ||
describe('.truncate()', () => { | ||
test('can read from beginning', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('can read from beginning', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { dir } = setup({ | ||
@@ -139,3 +131,3 @@ 'file.txt': '0123456789', | ||
describe('.write()', () => { | ||
test('can write to the file', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('can write to the file', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { dir, fs } = setup({ | ||
@@ -150,3 +142,3 @@ 'file.txt': '0123456789', | ||
})); | ||
test('can write at an offset', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('can write at an offset', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { dir, fs } = setup({ | ||
@@ -161,3 +153,3 @@ 'file.txt': '0123456789', | ||
})); | ||
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', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { dir, fs } = setup({ | ||
@@ -180,3 +172,3 @@ 'file.txt': '0123456789', | ||
// 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', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { dir, fs } = setup({ | ||
@@ -197,1 +189,2 @@ 'file.txt': '0123456789', | ||
}); | ||
//# 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 }); | ||
const tslib_1 = require("tslib"); | ||
const __1 = require("../.."); | ||
@@ -16,3 +8,3 @@ const FileHandle_1 = require("../../node/FileHandle"); | ||
describe('createSwapFile()', () => { | ||
test('can create a swap file', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('can create a swap file', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const fs = (0, __1.memfs)({ | ||
@@ -29,3 +21,3 @@ '/file.txt': 'Hello, world!', | ||
})); | ||
test('can create a swap file at subfolder', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('can create a swap file at subfolder', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const fs = (0, __1.memfs)({ | ||
@@ -42,3 +34,3 @@ '/foo/file.txt': 'Hello, world!', | ||
})); | ||
test('can create a swap file when the default swap file name is in use', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('can create a swap file when the default swap file name is in use', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const fs = (0, __1.memfs)({ | ||
@@ -57,3 +49,3 @@ '/foo/file.txt': 'Hello, world!', | ||
})); | ||
test('can create a swap file when the first two names are already taken', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('can create a swap file when the first two names are already taken', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const fs = (0, __1.memfs)({ | ||
@@ -74,3 +66,3 @@ '/foo/file.txt': 'Hello, world!', | ||
})); | ||
test('can create a swap file when the first three names are already taken', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('can create a swap file when the first three names are already taken', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const fs = (0, __1.memfs)({ | ||
@@ -93,3 +85,3 @@ '/foo/file.txt': 'Hello, world!', | ||
})); | ||
test('can copy existing data into the swap file', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('can copy existing data into the swap file', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const fs = (0, __1.memfs)({ | ||
@@ -113,1 +105,2 @@ '/foo/file.txt': 'Hello, world!', | ||
}); | ||
//# 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 }); | ||
const tslib_1 = require("tslib"); | ||
const __1 = require(".."); | ||
@@ -16,3 +8,3 @@ const __2 = 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* () { | ||
test('can init FSA from an arbitrary FS folder and execute operations', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const fs = (0, __2.memfs)({ | ||
@@ -48,1 +40,2 @@ '/tmp': 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)); | ||
} | ||
@@ -124,5 +92,5 @@ finally { if (e_1) throw e_1.error; } | ||
getDirectoryHandle(name, options) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
(0, util_1.assertName)(name, 'getDirectoryHandle', 'FileSystemDirectoryHandle'); | ||
const filename = this.__path + this.ctx.separator + name; | ||
const filename = this.__path + name; | ||
try { | ||
@@ -166,5 +134,5 @@ const stats = yield this.fs.promises.stat(filename); | ||
getFileHandle(name, options) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
(0, util_1.assertName)(name, 'getFileHandle', 'FileSystemDirectoryHandle'); | ||
const filename = this.__path + this.ctx.separator + name; | ||
const filename = this.__path + name; | ||
try { | ||
@@ -208,6 +176,6 @@ const stats = yield this.fs.promises.stat(filename); | ||
removeEntry(name, { recursive = false } = {}) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return tslib_1.__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 filename = this.__path + name; | ||
const promises = this.fs.promises; | ||
@@ -254,3 +222,3 @@ try { | ||
resolve(possibleDescendant) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
if (possibleDescendant instanceof NodeFileSystemDirectoryHandle || | ||
@@ -275,1 +243,2 @@ possibleDescendant instanceof NodeFileSystemFileHandle_1.NodeFileSystemFileHandle) { | ||
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 }); | ||
exports.NodeFileSystemFileHandle = void 0; | ||
const tslib_1 = require("tslib"); | ||
const NodeFileSystemHandle_1 = require("./NodeFileSystemHandle"); | ||
@@ -32,3 +24,3 @@ const NodeFileSystemSyncAccessHandle_1 = require("./NodeFileSystemSyncAccessHandle"); | ||
getFile() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
try { | ||
@@ -62,3 +54,3 @@ const path = this.__path; | ||
return undefined; | ||
return () => __awaiter(this, void 0, void 0, function* () { return new NodeFileSystemSyncAccessHandle_1.NodeFileSystemSyncAccessHandle(this.fs, this.__path, this.ctx); }); | ||
return () => tslib_1.__awaiter(this, void 0, void 0, function* () { return new NodeFileSystemSyncAccessHandle_1.NodeFileSystemSyncAccessHandle(this.fs, this.__path, this.ctx); }); | ||
} | ||
@@ -69,3 +61,3 @@ /** | ||
createWritable({ keepExistingData = false } = { keepExistingData: false }) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
(0, util_1.assertCanWrite)(this.ctx.mode); | ||
@@ -77,1 +69,2 @@ 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 }); | ||
exports.NodeFileSystemHandle = void 0; | ||
const tslib_1 = require("tslib"); | ||
/** | ||
@@ -42,3 +34,3 @@ * Represents a File System Access API file handle `FileSystemHandle` object, | ||
remove({ recursive } = { recursive: false }) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
throw new Error('Not implemented'); | ||
@@ -55,1 +47,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 }); | ||
exports.NodeFileSystemSyncAccessHandle = void 0; | ||
const tslib_1 = require("tslib"); | ||
const util_1 = require("./util"); | ||
@@ -28,3 +20,3 @@ /** | ||
close() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
(0, util_1.assertCanWrite)(this.ctx.mode); | ||
@@ -38,3 +30,3 @@ this.fs.closeSync(this.fd); | ||
flush() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
(0, util_1.assertCanWrite)(this.ctx.mode); | ||
@@ -48,3 +40,3 @@ this.fs.fsyncSync(this.fd); | ||
getSize() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
return this.fs.statSync(this.path).size; | ||
@@ -58,3 +50,3 @@ }); | ||
var _a; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const buf = buffer instanceof ArrayBuffer ? Buffer.from(buffer) : buffer; | ||
@@ -84,3 +76,3 @@ try { | ||
truncate(newSize) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
(0, util_1.assertCanWrite)(this.ctx.mode); | ||
@@ -100,3 +92,3 @@ this.fs.truncateSync(this.fd, newSize); | ||
var _a; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
(0, util_1.assertCanWrite)(this.ctx.mode); | ||
@@ -123,1 +115,2 @@ const buf = buffer instanceof ArrayBuffer ? Buffer.from(buffer) : buffer; | ||
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 }); | ||
exports.NodeFileSystemWritableFileStream = exports.createSwapFile = void 0; | ||
const tslib_1 = require("tslib"); | ||
/** | ||
@@ -22,3 +14,3 @@ * When Chrome writes to the file, it creates a copy of the file with extension | ||
*/ | ||
const createSwapFile = (fs, path, keepExistingData) => __awaiter(void 0, void 0, void 0, function* () { | ||
const createSwapFile = (fs, path, keepExistingData) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
let handle; | ||
@@ -65,3 +57,3 @@ let swapPath = path + '.crswap'; | ||
start() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const promise = (0, exports.createSwapFile)(fs, path, keepExistingData); | ||
@@ -75,3 +67,3 @@ swap.ready = promise.then(() => undefined); | ||
write(chunk) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
yield swap.ready; | ||
@@ -87,3 +79,3 @@ const handle = swap.handle; | ||
close() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
yield swap.ready; | ||
@@ -98,3 +90,3 @@ const handle = swap.handle; | ||
abort() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
yield swap.ready; | ||
@@ -119,3 +111,3 @@ const handle = swap.handle; | ||
seek(position) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
this.swap.offset = position; | ||
@@ -129,3 +121,3 @@ }); | ||
truncate(size) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
yield this.swap.ready; | ||
@@ -141,3 +133,3 @@ const handle = this.swap.handle; | ||
writeBase(chunk) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const writer = this.getWriter(); | ||
@@ -153,3 +145,3 @@ try { | ||
write(params) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
if (!params) | ||
@@ -205,1 +197,2 @@ throw new TypeError('Missing required 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,5 @@ /// <reference types="node" /> | ||
import * as opts from './node/types/options'; | ||
import { FsCallbackApi } from './node/types/FsCallbackApi'; | ||
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 +86,3 @@ code?: string; | ||
private promisesApi; | ||
get promises(): import("./node/types").FsPromisesApi; | ||
get promises(): FsPromisesApi; | ||
constructor(props?: {}); | ||
@@ -142,4 +143,2 @@ createLink(): Link; | ||
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; | ||
@@ -296,5 +295,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; | ||
@@ -337,2 +333,14 @@ 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']; | ||
cp: FsCallbackApi['cp']; | ||
lutimes: FsCallbackApi['lutimes']; | ||
statfs: FsCallbackApi['statfs']; | ||
writev: FsCallbackApi['writev']; | ||
readv: FsCallbackApi['readv']; | ||
openAsBlob: FsCallbackApi['openAsBlob']; | ||
opendir: FsCallbackApi['opendir']; | ||
} | ||
@@ -339,0 +347,0 @@ export declare class StatWatcher extends EventEmitter { |
@@ -23,1 +23,2 @@ "use strict"; | ||
} | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "memfs", | ||
"version": "4.1.0-next.2", | ||
"version": "4.1.0-next.3", | ||
"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": { | ||
@@ -93,4 +115,6 @@ "extends": [ | ||
}, | ||
"peerDependencies": { | ||
"tslib": "2" | ||
}, | ||
"dependencies": { | ||
"fs-monkey": "^1.0.4", | ||
"json-joy": "^9.2.0", | ||
@@ -120,8 +144,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", | ||
@@ -135,3 +159,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" | ||
} | ||
} |
@@ -36,2 +36,3 @@ # memfs | ||
- [`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) | ||
@@ -41,11 +42,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 | ||
- [`spyfs`][spyfs] - spies on filesystem actions | ||
[spyfs]: https://github.com/streamich/spyfs | ||
[unionfs]: https://github.com/streamich/unionfs | ||
[fs-monkey]: https://github.com/streamich/fs-monkey | ||
[linkfs]: https://github.com/streamich/linkfs | ||
[fs-monkey]: https://github.com/streamich/fs-monkey | ||
[spyfs]: https://github.com/streamich/spyfs | ||
@@ -52,0 +53,0 @@ |
Sorry, the diff of this file is too big to display
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 2 instances in 1 package
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
870610
259
11910
0
55
0
- Removedfs-monkey@^1.0.4
- Removedfs-monkey@1.0.6(transitive)