first commit

This commit is contained in:
Stefan Hacker
2026-04-03 09:38:48 +02:00
commit 37ad745546
47450 changed files with 3120798 additions and 0 deletions
+201
View File
@@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright 2026 Vadims @streamich Daleckis <vadimsdaleckis@gmail.com>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
+54
View File
@@ -0,0 +1,54 @@
# @jsonjoy.com/fs-node
In-memory filesystem with Node.js `fs`-compatible API.
## Installation
```bash
npm install @jsonjoy.com/fs-node
```
## Usage
```ts
import { Volume } from '@jsonjoy.com/fs-node';
const vol = new Volume();
vol.writeFileSync('/hello.txt', 'Hello, World!');
console.log(vol.readFileSync('/hello.txt', 'utf8')); // Hello, World!
```
### Create filesystem from JSON
```ts
import { Volume } from '@jsonjoy.com/fs-node';
const vol = Volume.fromJSON({
'/app/index.js': 'console.log("Hello");',
'/app/package.json': '{"name": "app"}',
});
console.log(vol.readdirSync('/app')); // ['index.js', 'package.json']
```
## API
The `Volume` class implements Node.js `fs` module's synchronous and callback APIs:
- `readFile`, `readFileSync`
- `writeFile`, `writeFileSync`
- `mkdir`, `mkdirSync`
- `readdir`, `readdirSync`
- `stat`, `statSync`
- `unlink`, `unlinkSync`
- ... and many more
It also exposes a `promises` property for the Promise-based API:
```ts
const data = await vol.promises.readFile('/hello.txt', 'utf8');
```
## License
Apache-2.0
+26
View File
@@ -0,0 +1,26 @@
import { Link } from '@jsonjoy.com/fs-core';
import * as opts from '@jsonjoy.com/fs-node-utils/lib/types/options';
import type { IDir, IDirent } from '@jsonjoy.com/fs-node-utils/lib/types/misc';
/**
* A directory stream, like `fs.Dir`.
*/
export declare class Dir implements IDir {
protected readonly link: Link;
protected options: opts.IOpendirOptions;
private iteratorInfo;
private closed;
private operationQueue;
constructor(link: Link, options: opts.IOpendirOptions);
private closeBase;
private readBase;
readonly 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>;
[Symbol.asyncDispose](): Promise<void>;
[Symbol.dispose](): void;
}
+186
View File
@@ -0,0 +1,186 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Dir = void 0;
const util_1 = require("./util");
const Dirent_1 = require("./Dirent");
const errors = require("@jsonjoy.com/fs-node-builtins/lib/internal/errors");
/**
* A directory stream, like `fs.Dir`.
*/
class Dir {
constructor(link, options) {
this.link = link;
this.options = options;
this.iteratorInfo = [];
this.closed = false;
this.operationQueue = null;
this.path = link.getPath();
this.iteratorInfo.push(link.children[Symbol.iterator]());
}
closeBase() {
// In a real filesystem implementation, this would close file descriptors
// For memfs, we just need to mark as closed
}
readBase(iteratorInfo) {
let done;
let value;
let name;
let link;
do {
do {
({ done, value } = iteratorInfo[iteratorInfo.length - 1].next());
if (!done) {
[name, link] = value;
}
else {
break;
}
} while (name === '.' || name === '..');
if (done) {
iteratorInfo.pop();
if (iteratorInfo.length === 0) {
break;
}
else {
done = false;
}
}
else {
if (this.options.recursive && link.children.size) {
iteratorInfo.push(link.children[Symbol.iterator]());
}
return Dirent_1.default.build(link, this.options.encoding);
}
} while (!done);
return null;
}
close(callback) {
// Promise-based close
if (callback === undefined) {
if (this.closed) {
return Promise.reject(new errors.Error('ERR_DIR_CLOSED'));
}
return new Promise((resolve, reject) => {
this.close(err => {
if (err)
reject(err);
else
resolve();
});
});
}
// Callback-based close
(0, util_1.validateCallback)(callback);
if (this.closed) {
process.nextTick(callback, new errors.Error('ERR_DIR_CLOSED'));
return;
}
if (this.operationQueue !== null) {
this.operationQueue.push(() => {
this.close(callback);
});
return;
}
this.closed = true;
try {
this.closeBase();
process.nextTick(callback);
}
catch (err) {
process.nextTick(callback, err);
}
}
closeSync() {
if (this.closed) {
throw new errors.Error('ERR_DIR_CLOSED');
}
if (this.operationQueue !== null) {
throw new errors.Error('ERR_DIR_CONCURRENT_OPERATION');
}
this.closed = true;
this.closeBase();
}
read(callback) {
// Promise-based read
if (callback === undefined) {
return new Promise((resolve, reject) => {
this.read((err, result) => {
if (err)
reject(err);
else
resolve(result ?? null);
});
});
}
// Callback-based read
(0, util_1.validateCallback)(callback);
if (this.closed) {
process.nextTick(callback, new errors.Error('ERR_DIR_CLOSED'));
return;
}
if (this.operationQueue !== null) {
this.operationQueue.push(() => {
this.read(callback);
});
return;
}
this.operationQueue = [];
try {
const result = this.readBase(this.iteratorInfo);
process.nextTick(() => {
const queue = this.operationQueue;
this.operationQueue = null;
for (const op of queue)
op();
callback(null, result);
});
}
catch (err) {
process.nextTick(() => {
const queue = this.operationQueue;
this.operationQueue = null;
for (const op of queue)
op();
callback(err);
});
}
}
readSync() {
if (this.closed) {
throw new errors.Error('ERR_DIR_CLOSED');
}
if (this.operationQueue !== null) {
throw new errors.Error('ERR_DIR_CONCURRENT_OPERATION');
}
return this.readBase(this.iteratorInfo);
}
[Symbol.asyncIterator]() {
return {
next: async () => {
try {
const dirEnt = await this.read();
if (dirEnt !== null) {
return { done: false, value: dirEnt };
}
else {
return { done: true, value: undefined };
}
}
catch (err) {
throw err;
}
},
[Symbol.asyncIterator]() {
return this;
},
};
}
[Symbol.asyncDispose]() {
return this.close();
}
[Symbol.dispose]() {
this.closeSync();
}
}
exports.Dir = Dir;
//# sourceMappingURL=Dir.js.map
File diff suppressed because one or more lines are too long
+26
View File
@@ -0,0 +1,26 @@
import { Link } from '@jsonjoy.com/fs-core';
import { TEncodingExtended, TDataOut } from '@jsonjoy.com/fs-node-utils';
import type { IDirent } from '@jsonjoy.com/fs-node-utils/lib/types/misc';
/**
* A directory entry, like `fs.Dirent`.
*/
export declare class Dirent implements IDirent {
static build(link: Link, encoding: TEncodingExtended | undefined): Dirent;
name: TDataOut;
parentPath: string;
private mode;
/**
* @deprecated Will be removed at any time.
* @see https://nodejs.org/api/deprecations.html#DEP0178
*/
path: string;
private _checkModeProperty;
isDirectory(): boolean;
isFile(): boolean;
isBlockDevice(): boolean;
isCharacterDevice(): boolean;
isSymbolicLink(): boolean;
isFIFO(): boolean;
isSocket(): boolean;
}
export default Dirent;
+56
View File
@@ -0,0 +1,56 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Dirent = void 0;
const fs_node_utils_1 = require("@jsonjoy.com/fs-node-utils");
const { S_IFMT, S_IFDIR, S_IFREG, S_IFBLK, S_IFCHR, S_IFLNK, S_IFIFO, S_IFSOCK } = fs_node_utils_1.constants;
/**
* A directory entry, like `fs.Dirent`.
*/
class Dirent {
constructor() {
this.name = '';
this.parentPath = '';
this.mode = 0;
/**
* @deprecated Will be removed at any time.
* @see https://nodejs.org/api/deprecations.html#DEP0178
*/
this.path = '';
}
static build(link, encoding) {
const dirent = new Dirent();
const { mode } = link.getNode();
dirent.name = (0, fs_node_utils_1.strToEncoding)(link.getName(), encoding);
dirent.mode = mode;
dirent.parentPath = link.getParentPath();
dirent.path = dirent.parentPath;
return dirent;
}
_checkModeProperty(property) {
return (this.mode & S_IFMT) === property;
}
isDirectory() {
return this._checkModeProperty(S_IFDIR);
}
isFile() {
return this._checkModeProperty(S_IFREG);
}
isBlockDevice() {
return this._checkModeProperty(S_IFBLK);
}
isCharacterDevice() {
return this._checkModeProperty(S_IFCHR);
}
isSymbolicLink() {
return this._checkModeProperty(S_IFLNK);
}
isFIFO() {
return this._checkModeProperty(S_IFIFO);
}
isSocket() {
return this._checkModeProperty(S_IFSOCK);
}
}
exports.Dirent = Dirent;
exports.default = Dirent;
//# sourceMappingURL=Dirent.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":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,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC;IAC1C,CAAC;IAED,cAAc;QACZ,OAAO,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC;IAC1C,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC;IAC1C,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAC;IAC3C,CAAC;CACF;AApDD,wBAoDC;AAED,kBAAe,MAAM,CAAC"}
+52
View File
@@ -0,0 +1,52 @@
import { EventEmitter } from '@jsonjoy.com/fs-node-builtins/lib/events';
import type * as opts from '@jsonjoy.com/fs-node-utils/lib/types/options';
import type { IFileHandle, IReadStream, IWriteStream, IStats, TData, TDataOut, TMode, TTime } from '@jsonjoy.com/fs-node-utils/lib/types/misc';
import type { FsCallbackApi } from '@jsonjoy.com/fs-node-utils';
export declare class FileHandle extends EventEmitter implements IFileHandle {
private fs;
private refs;
private closePromise;
private closeResolve?;
private closeReject?;
private position;
private readableWebStreamLocked;
fd: number;
constructor(fs: FsCallbackApi, fd: number);
getAsyncId(): number;
appendFile(data: TData, options?: opts.IAppendFileOptions | string): Promise<void>;
chmod(mode: TMode): Promise<void>;
chown(uid: number, gid: number): Promise<void>;
close(): Promise<void>;
datasync(): Promise<void>;
createReadStream(options?: opts.IFileHandleReadStreamOptions): IReadStream;
createWriteStream(options?: opts.IFileHandleWriteStreamOptions): IWriteStream;
readableWebStream(options?: opts.IReadableWebStreamOptions): ReadableStream;
read(buffer: Buffer | Uint8Array, offset: number, length: number, position?: number | null): Promise<TFileHandleReadResult>;
readv(buffers: ArrayBufferView[], position?: number | null | undefined): Promise<TFileHandleReadvResult>;
readFile(options?: opts.IReadFileOptions | string): Promise<TDataOut>;
stat(options?: opts.IFStatOptions): Promise<IStats>;
sync(): Promise<void>;
truncate(len?: number): Promise<void>;
utimes(atime: TTime, mtime: TTime): Promise<void>;
write(buffer: Buffer | Uint8Array, offset?: number, length?: number, position?: number | null): Promise<TFileHandleWriteResult>;
writev(buffers: ArrayBufferView[], position?: number | null | undefined): Promise<TFileHandleWritevResult>;
writeFile(data: TData, options?: opts.IWriteFileOptions): Promise<void>;
private ref;
private unref;
}
export interface TFileHandleReadResult {
bytesRead: number;
buffer: Buffer | Uint8Array;
}
export interface TFileHandleWriteResult {
bytesWritten: number;
buffer: Buffer | Uint8Array;
}
export interface TFileHandleReadvResult {
bytesRead: number;
buffers: ArrayBufferView[];
}
export interface TFileHandleWritevResult {
bytesWritten: number;
buffers: ArrayBufferView[];
}
+189
View File
@@ -0,0 +1,189 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FileHandle = void 0;
const util_1 = require("./util");
const events_1 = require("@jsonjoy.com/fs-node-builtins/lib/events");
class FileHandle extends events_1.EventEmitter {
constructor(fs, fd) {
super();
this.refs = 1;
this.closePromise = null;
this.position = 0;
this.readableWebStreamLocked = false;
this.fs = fs;
this.fd = fd;
}
getAsyncId() {
// Return a unique async ID for this file handle
// In a real implementation, this would be provided by the underlying system
return this.fd;
}
appendFile(data, options) {
return (0, util_1.promisify)(this.fs, 'appendFile')(this.fd, data, options);
}
chmod(mode) {
return (0, util_1.promisify)(this.fs, 'fchmod')(this.fd, mode);
}
chown(uid, gid) {
return (0, util_1.promisify)(this.fs, 'fchown')(this.fd, uid, gid);
}
close() {
if (this.fd === -1) {
return Promise.resolve();
}
if (this.closePromise) {
return this.closePromise;
}
this.refs--;
if (this.refs === 0) {
const currentFd = this.fd;
this.fd = -1;
this.closePromise = (0, util_1.promisify)(this.fs, 'close')(currentFd).finally(() => {
this.closePromise = null;
});
}
else {
this.closePromise = new Promise((resolve, reject) => {
this.closeResolve = resolve;
this.closeReject = reject;
}).finally(() => {
this.closePromise = null;
this.closeReject = undefined;
this.closeResolve = undefined;
});
}
this.emit('close');
return this.closePromise;
}
datasync() {
return (0, util_1.promisify)(this.fs, 'fdatasync')(this.fd);
}
createReadStream(options) {
return this.fs.createReadStream('', { ...options, fd: this });
}
createWriteStream(options) {
return this.fs.createWriteStream('', { ...options, fd: this });
}
readableWebStream(options = {}) {
const { type = 'bytes', autoClose = false } = options;
let position = 0;
if (this.fd === -1) {
throw new Error('The FileHandle is closed');
}
if (this.closePromise) {
throw new Error('The FileHandle is closing');
}
if (this.readableWebStreamLocked) {
throw new Error('An error will be thrown if this method is called more than once or is called after the FileHandle is closed or closing.');
}
this.readableWebStreamLocked = true;
this.ref();
const unlockAndCleanup = () => {
this.readableWebStreamLocked = false;
this.unref();
if (autoClose) {
this.close().catch(() => {
// Ignore close errors in cleanup
});
}
};
return new ReadableStream({
type: type === 'bytes' ? 'bytes' : undefined,
autoAllocateChunkSize: 16384,
pull: async (controller) => {
try {
const view = controller.byobRequest?.view;
if (!view) {
// Fallback for when BYOB is not available
const buffer = new Uint8Array(16384);
const result = await this.read(buffer, 0, buffer.length, position);
if (result.bytesRead === 0) {
controller.close();
unlockAndCleanup();
return;
}
position += result.bytesRead;
controller.enqueue(buffer.slice(0, result.bytesRead));
return;
}
const result = await this.read(view, view.byteOffset, view.byteLength, position);
if (result.bytesRead === 0) {
controller.close();
unlockAndCleanup();
return;
}
position += result.bytesRead;
controller.byobRequest.respond(result.bytesRead);
}
catch (error) {
controller.error(error);
unlockAndCleanup();
}
},
cancel: async () => {
unlockAndCleanup();
},
});
}
async read(buffer, offset, length, position) {
const readPosition = position !== null && position !== undefined ? position : this.position;
const result = await (0, util_1.promisify)(this.fs, 'read', bytesRead => ({ bytesRead, buffer }))(this.fd, buffer, offset, length, readPosition);
// Update internal position only if position was null/undefined
if (position === null || position === undefined) {
this.position += result.bytesRead;
}
return result;
}
readv(buffers, position) {
return (0, util_1.promisify)(this.fs, 'readv', bytesRead => ({ bytesRead, buffers }))(this.fd, buffers, position);
}
readFile(options) {
return (0, util_1.promisify)(this.fs, 'readFile')(this.fd, options);
}
stat(options) {
return (0, util_1.promisify)(this.fs, 'fstat')(this.fd, options);
}
sync() {
return (0, util_1.promisify)(this.fs, 'fsync')(this.fd);
}
truncate(len) {
return (0, util_1.promisify)(this.fs, 'ftruncate')(this.fd, len);
}
utimes(atime, mtime) {
return (0, util_1.promisify)(this.fs, 'futimes')(this.fd, atime, mtime);
}
async write(buffer, offset, length, position) {
const useInternalPosition = typeof position !== 'number';
const writePosition = useInternalPosition ? this.position : position;
const result = await (0, util_1.promisify)(this.fs, 'write', bytesWritten => ({ bytesWritten, buffer }))(this.fd, buffer, offset, length, writePosition);
// Update internal position only if position was null/undefined
if (useInternalPosition) {
this.position += result.bytesWritten;
}
return result;
}
writev(buffers, position) {
return (0, util_1.promisify)(this.fs, 'writev', bytesWritten => ({ bytesWritten, buffers }))(this.fd, buffers, position);
}
writeFile(data, options) {
return (0, util_1.promisify)(this.fs, 'writeFile')(this.fd, data, options);
}
// Implement Symbol.asyncDispose if available (ES2023+)
async [Symbol.asyncDispose]() {
await this.close();
}
ref() {
this.refs++;
}
unref() {
this.refs--;
if (this.refs === 0) {
this.fd = -1;
if (this.closeResolve) {
(0, util_1.promisify)(this.fs, 'close')(this.fd).then(this.closeResolve, this.closeReject);
}
}
}
}
exports.FileHandle = FileHandle;
//# sourceMappingURL=FileHandle.js.map
File diff suppressed because one or more lines are too long
+91
View File
@@ -0,0 +1,91 @@
import type * as opts from '@jsonjoy.com/fs-node-utils/lib/types/options';
import type * as misc from '@jsonjoy.com/fs-node-utils/lib/types/misc';
import type { FsCallbackApi, FsPromisesApi } from '@jsonjoy.com/fs-node-utils';
export declare class FsPromises implements FsPromisesApi {
protected readonly fs: FsCallbackApi;
readonly FileHandle: new (...args: unknown[]) => misc.IFileHandle;
readonly constants: {
O_RDONLY: number;
O_WRONLY: number;
O_RDWR: number;
S_IFMT: number;
S_IFREG: number;
S_IFDIR: number;
S_IFCHR: number;
S_IFBLK: number;
S_IFIFO: number;
S_IFLNK: number;
S_IFSOCK: number;
O_CREAT: number;
O_EXCL: number;
O_NOCTTY: number;
O_TRUNC: number;
O_APPEND: number;
O_DIRECTORY: number;
O_NOATIME: number;
O_NOFOLLOW: number;
O_SYNC: number;
O_SYMLINK: number;
O_DIRECT: number;
O_NONBLOCK: number;
S_IRWXU: number;
S_IRUSR: number;
S_IWUSR: number;
S_IXUSR: number;
S_IRWXG: number;
S_IRGRP: number;
S_IWGRP: number;
S_IXGRP: number;
S_IRWXO: number;
S_IROTH: number;
S_IWOTH: number;
S_IXOTH: number;
F_OK: number;
R_OK: number;
W_OK: number;
X_OK: number;
UV_FS_SYMLINK_DIR: number;
UV_FS_SYMLINK_JUNCTION: number;
UV_FS_COPYFILE_EXCL: number;
UV_FS_COPYFILE_FICLONE: number;
UV_FS_COPYFILE_FICLONE_FORCE: number;
COPYFILE_EXCL: number;
COPYFILE_FICLONE: number;
COPYFILE_FICLONE_FORCE: number;
};
constructor(fs: FsCallbackApi, FileHandle: new (...args: unknown[]) => misc.IFileHandle);
readonly cp: (...args: any[]) => Promise<any>;
readonly opendir: (...args: any[]) => Promise<any>;
readonly statfs: (...args: any[]) => Promise<any>;
readonly lutimes: (...args: any[]) => Promise<any>;
readonly glob: (...args: any[]) => Promise<any>;
readonly access: (...args: any[]) => Promise<any>;
readonly chmod: (...args: any[]) => Promise<any>;
readonly chown: (...args: any[]) => Promise<any>;
readonly copyFile: (...args: any[]) => Promise<any>;
readonly lchmod: (...args: any[]) => Promise<any>;
readonly lchown: (...args: any[]) => Promise<any>;
readonly link: (...args: any[]) => Promise<any>;
readonly lstat: (...args: any[]) => Promise<any>;
readonly mkdir: (...args: any[]) => Promise<any>;
readonly mkdtemp: (...args: any[]) => Promise<any>;
readonly readdir: (...args: any[]) => Promise<any>;
readonly readlink: (...args: any[]) => Promise<any>;
readonly realpath: (...args: any[]) => Promise<any>;
readonly rename: (...args: any[]) => Promise<any>;
readonly rmdir: (...args: any[]) => Promise<any>;
readonly rm: (...args: any[]) => Promise<any>;
readonly stat: (...args: any[]) => Promise<any>;
readonly symlink: (...args: any[]) => Promise<any>;
readonly truncate: (...args: any[]) => Promise<any>;
readonly unlink: (...args: any[]) => Promise<any>;
readonly utimes: (...args: any[]) => Promise<any>;
readonly readFile: (id: misc.TFileHandle, options?: opts.IReadFileOptions | string) => Promise<misc.TDataOut>;
readonly appendFile: (path: misc.TFileHandle, data: misc.TData, options?: opts.IAppendFileOptions | string) => Promise<void>;
readonly open: (path: misc.PathLike, flags?: misc.TFlags, mode?: misc.TMode) => Promise<any>;
readonly writeFile: (id: misc.TFileHandle, data: misc.TPromisesData, options?: opts.IWriteFileOptions) => Promise<void>;
readonly watch: (filename: misc.PathLike, options?: opts.IWatchOptions | string) => AsyncIterableIterator<{
eventType: string;
filename: string | Buffer;
}>;
}
+160
View File
@@ -0,0 +1,160 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FsPromises = void 0;
const util_1 = require("./util");
const fs_node_utils_1 = require("@jsonjoy.com/fs-node-utils");
// AsyncIterator implementation for promises.watch
class FSWatchAsyncIterator {
constructor(fs, path, options = {}) {
this.fs = fs;
this.path = path;
this.options = options;
this.eventQueue = [];
this.resolveQueue = [];
this.finished = false;
this.maxQueue = options.maxQueue || 2048;
this.overflow = options.overflow || 'ignore';
this.startWatching();
// Handle AbortSignal
if (options.signal) {
if (options.signal.aborted) {
this.finish();
return;
}
options.signal.addEventListener('abort', () => {
this.finish();
});
}
}
startWatching() {
try {
this.watcher = this.fs.watch(this.path, this.options, (eventType, filename) => {
this.enqueueEvent({ eventType, filename });
});
}
catch (error) {
// If we can't start watching, finish immediately
this.finish();
throw error;
}
}
enqueueEvent(event) {
if (this.finished)
return;
// Handle queue overflow
if (this.eventQueue.length >= this.maxQueue) {
if (this.overflow === 'throw') {
const error = new Error(`Watch queue overflow: more than ${this.maxQueue} events queued`);
this.finish(error);
return;
}
else {
// 'ignore' - drop the oldest event
this.eventQueue.shift();
}
}
this.eventQueue.push(event);
// If there's a waiting promise, resolve it
if (this.resolveQueue.length > 0) {
const { resolve } = this.resolveQueue.shift();
const nextEvent = this.eventQueue.shift();
resolve({ value: nextEvent, done: false });
}
}
finish(error) {
if (this.finished)
return;
this.finished = true;
if (this.watcher) {
this.watcher.close();
this.watcher = null;
}
// Resolve or reject all pending promises
while (this.resolveQueue.length > 0) {
const { resolve, reject } = this.resolveQueue.shift();
if (error) {
reject(error);
}
else {
resolve({ value: undefined, done: true });
}
}
}
async next() {
if (this.finished) {
return { value: undefined, done: true };
}
// If we have queued events, return one
if (this.eventQueue.length > 0) {
const event = this.eventQueue.shift();
return { value: event, done: false };
}
// Otherwise, wait for the next event
return new Promise((resolve, reject) => {
this.resolveQueue.push({ resolve, reject });
});
}
async return() {
this.finish();
return { value: undefined, done: true };
}
async throw(error) {
this.finish(error);
throw error;
}
[Symbol.asyncIterator]() {
return this;
}
}
class FsPromises {
constructor(fs, FileHandle) {
this.fs = fs;
this.FileHandle = FileHandle;
this.constants = fs_node_utils_1.constants;
this.cp = (0, util_1.promisify)(this.fs, 'cp');
this.opendir = (0, util_1.promisify)(this.fs, 'opendir');
this.statfs = (0, util_1.promisify)(this.fs, 'statfs');
this.lutimes = (0, util_1.promisify)(this.fs, 'lutimes');
this.glob = (0, util_1.promisify)(this.fs, 'glob');
this.access = (0, util_1.promisify)(this.fs, 'access');
this.chmod = (0, util_1.promisify)(this.fs, 'chmod');
this.chown = (0, util_1.promisify)(this.fs, 'chown');
this.copyFile = (0, util_1.promisify)(this.fs, 'copyFile');
this.lchmod = (0, util_1.promisify)(this.fs, 'lchmod');
this.lchown = (0, util_1.promisify)(this.fs, 'lchown');
this.link = (0, util_1.promisify)(this.fs, 'link');
this.lstat = (0, util_1.promisify)(this.fs, 'lstat');
this.mkdir = (0, util_1.promisify)(this.fs, 'mkdir');
this.mkdtemp = (0, util_1.promisify)(this.fs, 'mkdtemp');
this.readdir = (0, util_1.promisify)(this.fs, 'readdir');
this.readlink = (0, util_1.promisify)(this.fs, 'readlink');
this.realpath = (0, util_1.promisify)(this.fs, 'realpath');
this.rename = (0, util_1.promisify)(this.fs, 'rename');
this.rmdir = (0, util_1.promisify)(this.fs, 'rmdir');
this.rm = (0, util_1.promisify)(this.fs, 'rm');
this.stat = (0, util_1.promisify)(this.fs, 'stat');
this.symlink = (0, util_1.promisify)(this.fs, 'symlink');
this.truncate = (0, util_1.promisify)(this.fs, 'truncate');
this.unlink = (0, util_1.promisify)(this.fs, 'unlink');
this.utimes = (0, util_1.promisify)(this.fs, 'utimes');
this.readFile = (id, options) => {
return (0, util_1.promisify)(this.fs, 'readFile')(id instanceof this.FileHandle ? id.fd : id, options);
};
this.appendFile = (path, data, options) => {
return (0, util_1.promisify)(this.fs, 'appendFile')(path instanceof this.FileHandle ? path.fd : path, data, options);
};
this.open = (path, flags = 'r', mode) => {
return (0, util_1.promisify)(this.fs, 'open', fd => new this.FileHandle(this.fs, fd))(path, flags, mode);
};
this.writeFile = (id, data, options) => {
const dataPromise = (0, util_1.isReadableStream)(data) ? (0, util_1.streamToBuffer)(data) : Promise.resolve(data);
return dataPromise.then(data => (0, util_1.promisify)(this.fs, 'writeFile')(id instanceof this.FileHandle ? id.fd : id, data, options));
};
this.watch = (filename, options) => {
const watchOptions = typeof options === 'string' ? { encoding: options } : options || {};
return new FSWatchAsyncIterator(this.fs, filename, watchOptions);
};
}
}
exports.FsPromises = FsPromises;
//# sourceMappingURL=FsPromises.js.map
File diff suppressed because one or more lines are too long
+19
View File
@@ -0,0 +1,19 @@
import { Superblock } from '@jsonjoy.com/fs-core';
import type { IStatFs } from '@jsonjoy.com/fs-node-utils/lib/types/misc';
export type TStatNumber = number | bigint;
/**
* Statistics about a file system, like `fs.StatFs`.
*/
export declare class StatFs<T = TStatNumber> implements IStatFs<T> {
static build(superblock: Superblock, bigint: false): StatFs<number>;
static build(superblock: Superblock, bigint: true): StatFs<bigint>;
static build(superblock: Superblock, bigint?: boolean): StatFs<TStatNumber>;
type: T;
bsize: T;
blocks: T;
bfree: T;
bavail: T;
files: T;
ffree: T;
}
export default StatFs;
+34
View File
@@ -0,0 +1,34 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.StatFs = void 0;
/**
* Statistics about a file system, like `fs.StatFs`.
*/
class StatFs {
static build(superblock, bigint = false) {
const statfs = new StatFs();
const getStatNumber = !bigint ? number => number : number => BigInt(number);
// For in-memory filesystem, provide mock but reasonable values
// Magic number for in-memory filesystem type (similar to ramfs)
statfs.type = getStatNumber(0x858458f6);
// Optimal transfer block size - commonly 4096 bytes
statfs.bsize = getStatNumber(4096);
// Calculate filesystem stats based on current state
const totalInodes = Object.keys(superblock.inodes).length;
// Mock large filesystem capacity (appears as a large filesystem to applications)
const totalBlocks = 1000000;
const usedBlocks = Math.min(totalInodes * 2, totalBlocks); // Rough estimation
const freeBlocks = totalBlocks - usedBlocks;
statfs.blocks = getStatNumber(totalBlocks); // Total data blocks
statfs.bfree = getStatNumber(freeBlocks); // Free blocks in file system
statfs.bavail = getStatNumber(freeBlocks); // Free blocks available to unprivileged users
// File node statistics
const maxFiles = 1000000; // Mock large number of available inodes
statfs.files = getStatNumber(maxFiles); // Total file nodes in file system
statfs.ffree = getStatNumber(maxFiles - totalInodes); // Free file nodes
return statfs;
}
}
exports.StatFs = StatFs;
exports.default = StatFs;
//# sourceMappingURL=StatFs.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"StatFs.js","sourceRoot":"","sources":["../src/StatFs.ts"],"names":[],"mappings":";;;AAKA;;GAEG;AACH,MAAa,MAAM;IAIjB,MAAM,CAAC,KAAK,CAAC,UAAsB,EAAE,SAAkB,KAAK;QAC1D,MAAM,MAAM,GAAG,IAAI,MAAM,EAAe,CAAC;QAEzC,MAAM,aAAa,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAE5E,+DAA+D;QAC/D,gEAAgE;QAChE,MAAM,CAAC,IAAI,GAAG,aAAa,CAAC,UAAU,CAAC,CAAC;QAExC,oDAAoD;QACpD,MAAM,CAAC,KAAK,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC;QAEnC,oDAAoD;QACpD,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC;QAE1D,iFAAiF;QACjF,MAAM,WAAW,GAAG,OAAO,CAAC;QAC5B,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,WAAW,GAAG,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,mBAAmB;QAC9E,MAAM,UAAU,GAAG,WAAW,GAAG,UAAU,CAAC;QAE5C,MAAM,CAAC,MAAM,GAAG,aAAa,CAAC,WAAW,CAAC,CAAC,CAAC,oBAAoB;QAChE,MAAM,CAAC,KAAK,GAAG,aAAa,CAAC,UAAU,CAAC,CAAC,CAAC,6BAA6B;QACvE,MAAM,CAAC,MAAM,GAAG,aAAa,CAAC,UAAU,CAAC,CAAC,CAAC,8CAA8C;QAEzF,uBAAuB;QACvB,MAAM,QAAQ,GAAG,OAAO,CAAC,CAAC,wCAAwC;QAClE,MAAM,CAAC,KAAK,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAC,CAAC,kCAAkC;QAC1E,MAAM,CAAC,KAAK,GAAG,aAAa,CAAC,QAAQ,GAAG,WAAW,CAAC,CAAC,CAAC,kBAAkB;QAExE,OAAO,MAAM,CAAC;IAChB,CAAC;CASF;AA3CD,wBA2CC;AAED,kBAAe,MAAM,CAAC"}
+41
View File
@@ -0,0 +1,41 @@
import { Node } from '@jsonjoy.com/fs-core';
export type TStatNumber = number | bigint;
/**
* Statistics about a file/directory, like `fs.Stats`.
*/
export declare class Stats<T = TStatNumber> {
static build(node: Node, bigint: false): Stats<number>;
static build(node: Node, bigint: true): Stats<bigint>;
static build(node: Node, bigint?: boolean): Stats<TStatNumber>;
uid: T;
gid: T;
rdev: T;
blksize: T;
ino: T;
size: T;
blocks: T;
atime: Date;
mtime: Date;
ctime: Date;
birthtime: Date;
atimeMs: T;
mtimeMs: T;
ctimeMs: T;
birthtimeMs: T;
atimeNs: T extends bigint ? T : undefined;
mtimeNs: T extends bigint ? T : undefined;
ctimeNs: T extends bigint ? T : undefined;
birthtimeNs: T extends bigint ? T : undefined;
dev: T;
mode: T;
nlink: T;
private _checkModeProperty;
isDirectory(): boolean;
isFile(): boolean;
isBlockDevice(): boolean;
isCharacterDevice(): boolean;
isSymbolicLink(): boolean;
isFIFO(): boolean;
isSocket(): boolean;
}
export default Stats;
+72
View File
@@ -0,0 +1,72 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Stats = void 0;
const fs_node_utils_1 = require("@jsonjoy.com/fs-node-utils");
const { S_IFMT, S_IFDIR, S_IFREG, S_IFBLK, S_IFCHR, S_IFLNK, S_IFIFO, S_IFSOCK } = fs_node_utils_1.constants;
/**
* Statistics about a file/directory, like `fs.Stats`.
*/
class Stats {
static build(node, bigint = false) {
const stats = new Stats();
const { uid, gid, atime, mtime, ctime } = node;
const getStatNumber = !bigint ? number => number : number => BigInt(number);
// Copy all values on Stats from Node, so that if Node values
// change, values on Stats would still be the old ones,
// just like in Node fs.
stats.uid = getStatNumber(uid);
stats.gid = getStatNumber(gid);
stats.rdev = getStatNumber(node.rdev);
stats.blksize = getStatNumber(4096);
stats.ino = getStatNumber(node.ino);
stats.size = getStatNumber(node.getSize());
stats.blocks = getStatNumber(1);
stats.atime = atime;
stats.mtime = mtime;
stats.ctime = ctime;
stats.birthtime = ctime;
stats.atimeMs = getStatNumber(atime.getTime());
stats.mtimeMs = getStatNumber(mtime.getTime());
const ctimeMs = getStatNumber(ctime.getTime());
stats.ctimeMs = ctimeMs;
stats.birthtimeMs = ctimeMs;
if (bigint) {
stats.atimeNs = BigInt(atime.getTime()) * BigInt(1000000);
stats.mtimeNs = BigInt(mtime.getTime()) * BigInt(1000000);
const ctimeNs = BigInt(ctime.getTime()) * BigInt(1000000);
stats.ctimeNs = ctimeNs;
stats.birthtimeNs = ctimeNs;
}
stats.dev = getStatNumber(0);
stats.mode = getStatNumber(node.mode);
stats.nlink = getStatNumber(node.nlink);
return stats;
}
_checkModeProperty(property) {
return (Number(this.mode) & S_IFMT) === property;
}
isDirectory() {
return this._checkModeProperty(S_IFDIR);
}
isFile() {
return this._checkModeProperty(S_IFREG);
}
isBlockDevice() {
return this._checkModeProperty(S_IFBLK);
}
isCharacterDevice() {
return this._checkModeProperty(S_IFCHR);
}
isSymbolicLink() {
return this._checkModeProperty(S_IFLNK);
}
isFIFO() {
return this._checkModeProperty(S_IFIFO);
}
isSocket() {
return this._checkModeProperty(S_IFSOCK);
}
}
exports.Stats = Stats;
exports.default = Stats;
//# sourceMappingURL=Stats.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"Stats.js","sourceRoot":"","sources":["../src/Stats.ts"],"names":[],"mappings":";;;AACA,8DAAuD;AAEvD,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,yBAAS,CAAC;AAI7F;;GAEG;AACH,MAAa,KAAK;IAIhB,MAAM,CAAC,KAAK,CAAC,IAAU,EAAE,SAAkB,KAAK;QAC9C,MAAM,KAAK,GAAG,IAAI,KAAK,EAAe,CAAC;QACvC,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;QAE/C,MAAM,aAAa,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAE5E,6DAA6D;QAC7D,uDAAuD;QACvD,wBAAwB;QAExB,KAAK,CAAC,GAAG,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC;QAC/B,KAAK,CAAC,GAAG,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC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,KAAK,CAAC,WAAW,GAAG,OAAO,CAAC;QAC9B,CAAC;QAED,KAAK,CAAC,GAAG,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC;QAC7B,KAAK,CAAC,IAAI,GAAG,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACtC,KAAK,CAAC,KAAK,GAAG,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAExC,OAAO,KAAK,CAAC;IACf,CAAC;IA+BO,kBAAkB,CAAC,QAAgB;QACzC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,KAAK,QAAQ,CAAC;IACnD,CAAC;IAED,WAAW;QACT,OAAO,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC;IAC1C,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC;IAC1C,CAAC;IAED,aAAa;QACX,OAAO,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC;IAC1C,CAAC;IAED,iBAAiB;QACf,OAAO,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC;IAC1C,CAAC;IAED,cAAc;QACZ,OAAO,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC;IAC1C,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC;IAC1C,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAC;IAC3C,CAAC;CACF;AA7GD,sBA6GC;AAED,kBAAe,KAAK,CAAC"}
+5
View File
@@ -0,0 +1,5 @@
import { IGlobOptions } from '@jsonjoy.com/fs-node-utils/lib/types/options';
/**
* Main glob implementation
*/
export declare function globSync(fs: any, pattern: string, options?: IGlobOptions): string[];
+95
View File
@@ -0,0 +1,95 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.globSync = globSync;
const path_1 = require("@jsonjoy.com/fs-node-builtins/lib/path");
const glob_to_regex_js_1 = require("glob-to-regex.js");
const util_1 = require("./util");
const pathJoin = path_1.posix.join;
const pathRelative = path_1.posix.relative;
const pathResolve = path_1.posix.resolve;
/**
* Check if a path matches a glob pattern
*/
function matchesPattern(path, pattern) {
const regex = (0, glob_to_regex_js_1.toRegex)(pattern);
return regex.test(path);
}
/**
* Check if a path should be excluded based on exclude patterns
*/
function isExcluded(path, exclude) {
if (!exclude)
return false;
if (typeof exclude === 'function') {
return exclude(path);
}
const patterns = Array.isArray(exclude) ? exclude : [exclude];
return patterns.some(pattern => matchesPattern(path, pattern));
}
/**
* Walk directory tree and collect matching paths
*/
function walkDirectory(fs, dir, patterns, options, currentDepth = 0) {
const results = [];
const maxDepth = options.maxdepth ?? Infinity;
const baseCwd = options.cwd ? (0, util_1.pathToFilename)(options.cwd) : process.cwd();
if (currentDepth > maxDepth) {
return results;
}
try {
const entries = fs.readdirSync(dir, { withFileTypes: true });
for (const entry of entries) {
const fullPath = pathJoin(dir, entry.name.toString());
const relativePath = pathRelative(baseCwd, fullPath);
// Skip if excluded
if (isExcluded(relativePath, options.exclude)) {
continue;
}
// Check if this path matches any pattern
const matches = patterns.some(pattern => matchesPattern(relativePath, pattern));
if (matches) {
results.push(relativePath);
}
// Recurse into directories
if (entry.isDirectory() && currentDepth < maxDepth) {
const subResults = walkDirectory(fs, fullPath, patterns, options, currentDepth + 1);
results.push(...subResults);
}
}
}
catch (err) {
// Skip directories we can't read
}
return results;
}
/**
* Main glob implementation
*/
function globSync(fs, pattern, options = {}) {
const cwd = options.cwd ? (0, util_1.pathToFilename)(options.cwd) : process.cwd();
const resolvedCwd = pathResolve(cwd);
const globOptions = {
cwd: resolvedCwd,
exclude: options.exclude,
maxdepth: options.maxdepth,
withFileTypes: options.withFileTypes || false,
};
let results = [];
// Handle absolute patterns
if (path_1.posix.isAbsolute(pattern)) {
const dir = path_1.posix.dirname(pattern);
const patternBasename = path_1.posix.basename(pattern);
const dirResults = walkDirectory(fs, dir, [patternBasename], { ...globOptions, cwd: dir });
results.push(...dirResults.map(r => path_1.posix.resolve(dir, r)));
}
else {
// Handle relative patterns - normalize by stripping leading './'
const normalizedPattern = pattern.replace(/^\.\//, '');
const dirResults = walkDirectory(fs, resolvedCwd, [normalizedPattern], globOptions);
results.push(...dirResults);
}
// Remove duplicates and sort
results = [...new Set(results)].sort();
return results;
}
//# sourceMappingURL=glob.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"glob.js","sourceRoot":"","sources":["../src/glob.ts"],"names":[],"mappings":";;AA8EA,4BA8BC;AA5GD,iEAA+D;AAC/D,uDAA2C;AAE3C,iCAAwC;AAGxC,MAAM,QAAQ,GAAG,YAAK,CAAC,IAAI,CAAC;AAC5B,MAAM,YAAY,GAAG,YAAK,CAAC,QAAQ,CAAC;AACpC,MAAM,WAAW,GAAG,YAAK,CAAC,OAAO,CAAC;AAElC;;GAEG;AACH,SAAS,cAAc,CAAC,IAAY,EAAE,OAAe;IACnD,MAAM,KAAK,GAAG,IAAA,0BAAO,EAAC,OAAO,CAAC,CAAC;IAC/B,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC;AAED;;GAEG;AACH,SAAS,UAAU,CAAC,IAAY,EAAE,OAAoE;IACpG,IAAI,CAAC,OAAO;QAAE,OAAO,KAAK,CAAC;IAE3B,IAAI,OAAO,OAAO,KAAK,UAAU,EAAE,CAAC;QAClC,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC;IACvB,CAAC;IAED,MAAM,QAAQ,GAAG,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;IAC9D,OAAO,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,cAAc,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;AACjE,CAAC;AA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AAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IAC9D,CAAC;SAAM,CAAC;QACN,iEAAiE;QACjE,MAAM,iBAAiB,GAAG,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;QACvD,MAAM,UAAU,GAAG,aAAa,CAAC,EAAE,EAAE,WAAW,EAAE,CAAC,iBAAiB,CAAC,EAAE,WAAW,CAAC,CAAC;QACpF,OAAO,CAAC,IAAI,CAAC,GAAG,UAAU,CAAC,CAAC;IAC9B,CAAC;IAED,6BAA6B;IAC7B,OAAO,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IAEvC,OAAO,OAAO,CAAC;AACjB,CAAC"}
+16
View File
@@ -0,0 +1,16 @@
export { Volume, StatWatcher, FSWatcher, toUnixTimestamp } from './volume';
export type { IWriteStream, IError, IAppendFileOptions, IWatchFileOptions, IWatchOptions } from './volume';
export { default as Stats, TStatNumber } from './Stats';
export { default as Dirent } from './Dirent';
export { default as StatFs } from './StatFs';
export { FileHandle } from './FileHandle';
export { Dir } from './Dir';
export { FsPromises } from './FsPromises';
export * from './options';
export * from './util';
export * from './glob';
export { fsCallbackApiList } from './lists/fsCallbackApiList';
export { fsSynchronousApiList } from './lists/fsSynchronousApiList';
export { fsCommonObjectsList } from './lists/fsCommonObjectsList';
export type { FsCommonObjects } from './types/FsCommonObjects';
export type { FsPromisesApi } from './types/FsPromisesApi';
+31
View File
@@ -0,0 +1,31 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.fsCommonObjectsList = exports.fsSynchronousApiList = exports.fsCallbackApiList = exports.FsPromises = exports.Dir = exports.FileHandle = exports.StatFs = exports.Dirent = exports.Stats = exports.toUnixTimestamp = exports.FSWatcher = exports.StatWatcher = exports.Volume = void 0;
const tslib_1 = require("tslib");
var volume_1 = require("./volume");
Object.defineProperty(exports, "Volume", { enumerable: true, get: function () { return volume_1.Volume; } });
Object.defineProperty(exports, "StatWatcher", { enumerable: true, get: function () { return volume_1.StatWatcher; } });
Object.defineProperty(exports, "FSWatcher", { enumerable: true, get: function () { return volume_1.FSWatcher; } });
Object.defineProperty(exports, "toUnixTimestamp", { enumerable: true, get: function () { return volume_1.toUnixTimestamp; } });
var Stats_1 = require("./Stats");
Object.defineProperty(exports, "Stats", { enumerable: true, get: function () { return Stats_1.default; } });
var Dirent_1 = require("./Dirent");
Object.defineProperty(exports, "Dirent", { enumerable: true, get: function () { return Dirent_1.default; } });
var StatFs_1 = require("./StatFs");
Object.defineProperty(exports, "StatFs", { enumerable: true, get: function () { return StatFs_1.default; } });
var FileHandle_1 = require("./FileHandle");
Object.defineProperty(exports, "FileHandle", { enumerable: true, get: function () { return FileHandle_1.FileHandle; } });
var Dir_1 = require("./Dir");
Object.defineProperty(exports, "Dir", { enumerable: true, get: function () { return Dir_1.Dir; } });
var FsPromises_1 = require("./FsPromises");
Object.defineProperty(exports, "FsPromises", { enumerable: true, get: function () { return FsPromises_1.FsPromises; } });
tslib_1.__exportStar(require("./options"), exports);
tslib_1.__exportStar(require("./util"), exports);
tslib_1.__exportStar(require("./glob"), exports);
var fsCallbackApiList_1 = require("./lists/fsCallbackApiList");
Object.defineProperty(exports, "fsCallbackApiList", { enumerable: true, get: function () { return fsCallbackApiList_1.fsCallbackApiList; } });
var fsSynchronousApiList_1 = require("./lists/fsSynchronousApiList");
Object.defineProperty(exports, "fsSynchronousApiList", { enumerable: true, get: function () { return fsSynchronousApiList_1.fsSynchronousApiList; } });
var fsCommonObjectsList_1 = require("./lists/fsCommonObjectsList");
Object.defineProperty(exports, "fsCommonObjectsList", { enumerable: true, get: function () { return fsCommonObjectsList_1.fsCommonObjectsList; } });
//# sourceMappingURL=index.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;AAAA,mCAA2E;AAAlE,gGAAA,MAAM,OAAA;AAAE,qGAAA,WAAW,OAAA;AAAE,mGAAA,SAAS,OAAA;AAAE,yGAAA,eAAe,OAAA;AAExD,iCAAwD;AAA/C,8FAAA,OAAO,OAAS;AACzB,mCAA6C;AAApC,gGAAA,OAAO,OAAU;AAC1B,mCAA6C;AAApC,gGAAA,OAAO,OAAU;AAC1B,2CAA0C;AAAjC,wGAAA,UAAU,OAAA;AACnB,6BAA4B;AAAnB,0FAAA,GAAG,OAAA;AACZ,2CAA0C;AAAjC,wGAAA,UAAU,OAAA;AACnB,oDAA0B;AAC1B,iDAAuB;AACvB,iDAAuB;AACvB,+DAA8D;AAArD,sHAAA,iBAAiB,OAAA;AAC1B,qEAAoE;AAA3D,4HAAA,oBAAoB,OAAA;AAC7B,mEAAkE;AAAzD,0HAAA,mBAAmB,OAAA"}
+2
View File
@@ -0,0 +1,2 @@
import type { FsCallbackApi } from '@jsonjoy.com/fs-node-utils';
export declare const fsCallbackApiList: Array<keyof FsCallbackApi>;
+55
View File
@@ -0,0 +1,55 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.fsCallbackApiList = void 0;
exports.fsCallbackApiList = [
'access',
'appendFile',
'chmod',
'chown',
'close',
'copyFile',
'cp',
'createReadStream',
'createWriteStream',
'exists',
'fchmod',
'fchown',
'fdatasync',
'fstat',
'fsync',
'ftruncate',
'futimes',
'glob',
'lchmod',
'lchown',
'link',
'lstat',
'mkdir',
'mkdtemp',
'open',
'openAsBlob',
'opendir',
'read',
'readv',
'readdir',
'readFile',
'readlink',
'realpath',
'rename',
'rm',
'rmdir',
'stat',
'statfs',
'symlink',
'truncate',
'unlink',
'unwatchFile',
'utimes',
'lutimes',
'watch',
'watchFile',
'write',
'writev',
'writeFile',
];
//# sourceMappingURL=fsCallbackApiList.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"fsCallbackApiList.js","sourceRoot":"","sources":["../../src/lists/fsCallbackApiList.ts"],"names":[],"mappings":";;;AAEa,QAAA,iBAAiB,GAA+B;IAC3D,QAAQ;IACR,YAAY;IACZ,OAAO;IACP,OAAO;IACP,OAAO;IACP,UAAU;IACV,IAAI;IACJ,kBAAkB;IAClB,mBAAmB;IACnB,QAAQ;IACR,QAAQ;IACR,QAAQ;IACR,WAAW;IACX,OAAO;IACP,OAAO;IACP,WAAW;IACX,SAAS;IACT,MAAM;IACN,QAAQ;IACR,QAAQ;IACR,MAAM;IACN,OAAO;IACP,OAAO;IACP,SAAS;IACT,MAAM;IACN,YAAY;IACZ,SAAS;IACT,MAAM;IACN,OAAO;IACP,SAAS;IACT,UAAU;IACV,UAAU;IACV,UAAU;IACV,QAAQ;IACR,IAAI;IACJ,OAAO;IACP,MAAM;IACN,QAAQ;IACR,SAAS;IACT,UAAU;IACV,QAAQ;IACR,aAAa;IACb,QAAQ;IACR,SAAS;IACT,OAAO;IACP,WAAW;IACX,OAAO;IACP,QAAQ;IACR,WAAW;CACZ,CAAC"}
+2
View File
@@ -0,0 +1,2 @@
import type { FsCommonObjects } from '../types/FsCommonObjects';
export declare const fsCommonObjectsList: Array<keyof FsCommonObjects>;
+19
View File
@@ -0,0 +1,19 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.fsCommonObjectsList = void 0;
exports.fsCommonObjectsList = [
'F_OK',
'R_OK',
'W_OK',
'X_OK',
'constants',
'Stats',
'StatFs',
'Dir',
'Dirent',
'StatsWatcher',
'FSWatcher',
'ReadStream',
'WriteStream',
];
//# sourceMappingURL=fsCommonObjectsList.js.map
@@ -0,0 +1 @@
{"version":3,"file":"fsCommonObjectsList.js","sourceRoot":"","sources":["../../src/lists/fsCommonObjectsList.ts"],"names":[],"mappings":";;;AAEa,QAAA,mBAAmB,GAAiC;IAC/D,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,WAAW;IACX,OAAO;IACP,QAAQ;IACR,KAAK;IACL,QAAQ;IACR,cAAc;IACd,WAAW;IACX,YAAY;IACZ,aAAa;CACd,CAAC"}
@@ -0,0 +1,2 @@
import type { FsSynchronousApi } from '@jsonjoy.com/fs-node-utils';
export declare const fsSynchronousApiList: Array<keyof FsSynchronousApi>;
+49
View File
@@ -0,0 +1,49 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.fsSynchronousApiList = void 0;
exports.fsSynchronousApiList = [
'accessSync',
'appendFileSync',
'chmodSync',
'chownSync',
'closeSync',
'copyFileSync',
'existsSync',
'fchmodSync',
'fchownSync',
'fdatasyncSync',
'fstatSync',
'fsyncSync',
'ftruncateSync',
'futimesSync',
'globSync',
'lchmodSync',
'lchownSync',
'linkSync',
'lstatSync',
'mkdirSync',
'mkdtempSync',
'openSync',
'opendirSync',
'readdirSync',
'readFileSync',
'readlinkSync',
'readSync',
'readvSync',
'realpathSync',
'renameSync',
'rmdirSync',
'rmSync',
'statSync',
'symlinkSync',
'truncateSync',
'unlinkSync',
'utimesSync',
'lutimesSync',
'writeFileSync',
'writeSync',
'writevSync',
// 'cpSync',
// 'statfsSync',
];
//# sourceMappingURL=fsSynchronousApiList.js.map
@@ -0,0 +1 @@
{"version":3,"file":"fsSynchronousApiList.js","sourceRoot":"","sources":["../../src/lists/fsSynchronousApiList.ts"],"names":[],"mappings":";;;AAEa,QAAA,oBAAoB,GAAkC;IACjE,YAAY;IACZ,gBAAgB;IAChB,WAAW;IACX,WAAW;IACX,WAAW;IACX,cAAc;IACd,YAAY;IACZ,YAAY;IACZ,YAAY;IACZ,eAAe;IACf,WAAW;IACX,WAAW;IACX,eAAe;IACf,aAAa;IACb,UAAU;IACV,YAAY;IACZ,YAAY;IACZ,UAAU;IACV,WAAW;IACX,WAAW;IACX,aAAa;IACb,UAAU;IACV,aAAa;IACb,aAAa;IACb,cAAc;IACd,cAAc;IACd,UAAU;IACV,WAAW;IACX,cAAc;IACd,YAAY;IACZ,WAAW;IACX,QAAQ;IACR,UAAU;IACV,aAAa;IACb,cAAc;IACd,YAAY;IACZ,YAAY;IACZ,aAAa;IACb,eAAe;IACf,WAAW;IACX,YAAY;IAEZ,YAAY;IACZ,gBAAgB;CACjB,CAAC"}
+27
View File
@@ -0,0 +1,27 @@
import type * as opts from '@jsonjoy.com/fs-node-utils/lib/types/options';
import * as misc from '@jsonjoy.com/fs-node-utils/lib/types/misc';
import { IAppendFileOptions } from './volume';
export declare const getMkdirOptions: (options: any) => opts.IMkdirOptions;
export declare function getOptions<T extends opts.IOptions>(defaults: T, options?: T | string): T;
export declare function optsGenerator<TOpts>(defaults: TOpts): (opts: any) => TOpts;
export declare function optsAndCbGenerator<TOpts, TResult>(getOpts: any): (options: any, callback?: any) => [TOpts, misc.TCallback<TResult>];
export declare const optsDefaults: opts.IOptions;
export declare const getDefaultOpts: (opts: any) => opts.IOptions;
export declare const getDefaultOptsAndCb: (options: any, callback?: any) => [opts.IOptions, misc.TCallback<any>];
export declare const getRmdirOptions: (options: any) => opts.IRmdirOptions;
export declare const getRmOptsAndCb: (options: any, callback?: any) => [opts.IRmOptions, misc.TCallback<any>];
export declare const getReadFileOptions: (opts: any) => opts.IReadFileOptions;
export declare const getReaddirOptions: (opts: any) => opts.IReaddirOptions;
export declare const getReaddirOptsAndCb: (options: any, callback?: any) => [opts.IReaddirOptions, misc.TCallback<misc.TDataOut[] | misc.IDirent[]>];
export declare const getOpendirOptions: (opts: any) => opts.IOpendirOptions;
export declare const getOpendirOptsAndCb: (options: any, callback?: any) => [opts.IOpendirOptions, misc.TCallback<misc.IDir>];
export declare const getAppendFileOpts: (opts: any) => IAppendFileOptions;
export declare const getAppendFileOptsAndCb: (options: any, callback?: any) => [IAppendFileOptions, misc.TCallback<void>];
export declare const getStatOptions: (options?: any) => opts.IStatOptions;
export declare const getStatOptsAndCb: (options: any, callback?: misc.TCallback<misc.IStats>) => [opts.IStatOptions, misc.TCallback<misc.IStats>];
export declare const getStatfsOptions: (options?: any) => opts.IStafsOptions;
export declare const getStatfsOptsAndCb: (options: any, callback?: misc.TCallback<misc.IStatFs>) => [opts.IStafsOptions, misc.TCallback<misc.IStatFs>];
export declare const getRealpathOptions: (opts: any) => opts.IRealpathOptions;
export declare const getRealpathOptsAndCb: (options: any, callback?: any) => [opts.IRealpathOptions, misc.TCallback<misc.TDataOut>];
export declare const writeFileDefaults: opts.IWriteFileOptions;
export declare const getWriteFileOptions: (opts: any) => opts.IWriteFileOptions;
+111
View File
@@ -0,0 +1,111 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getWriteFileOptions = exports.writeFileDefaults = exports.getRealpathOptsAndCb = exports.getRealpathOptions = exports.getStatfsOptsAndCb = exports.getStatfsOptions = exports.getStatOptsAndCb = exports.getStatOptions = exports.getAppendFileOptsAndCb = exports.getAppendFileOpts = exports.getOpendirOptsAndCb = exports.getOpendirOptions = exports.getReaddirOptsAndCb = exports.getReaddirOptions = exports.getReadFileOptions = exports.getRmOptsAndCb = exports.getRmdirOptions = exports.getDefaultOptsAndCb = exports.getDefaultOpts = exports.optsDefaults = exports.getMkdirOptions = void 0;
exports.getOptions = getOptions;
exports.optsGenerator = optsGenerator;
exports.optsAndCbGenerator = optsAndCbGenerator;
const fs_node_utils_1 = require("@jsonjoy.com/fs-node-utils");
const util_1 = require("./util");
const mkdirDefaults = {
mode: 511 /* MODE.DIR */,
recursive: false,
};
const getMkdirOptions = (options) => {
if (typeof options === 'number')
return Object.assign({}, mkdirDefaults, { mode: options });
return Object.assign({}, mkdirDefaults, options);
};
exports.getMkdirOptions = getMkdirOptions;
const ERRSTR_OPTS = tipeof => `Expected options to be either an object or a string, but got ${tipeof} instead`;
function getOptions(defaults, options) {
let opts;
if (!options)
return defaults;
else {
const tipeof = typeof options;
switch (tipeof) {
case 'string':
opts = Object.assign({}, defaults, { encoding: options });
break;
case 'object':
opts = Object.assign({}, defaults, options);
break;
default:
throw TypeError(ERRSTR_OPTS(tipeof));
}
}
if (opts.encoding !== 'buffer')
(0, fs_node_utils_1.assertEncoding)(opts.encoding);
return opts;
}
function optsGenerator(defaults) {
return options => getOptions(defaults, options);
}
function optsAndCbGenerator(getOpts) {
return (options, callback) => typeof options === 'function' ? [getOpts(), options] : [getOpts(options), (0, util_1.validateCallback)(callback)];
}
exports.optsDefaults = {
encoding: 'utf8',
};
exports.getDefaultOpts = optsGenerator(exports.optsDefaults);
exports.getDefaultOptsAndCb = optsAndCbGenerator(exports.getDefaultOpts);
const rmdirDefaults = {
recursive: false,
};
const getRmdirOptions = (options) => {
return Object.assign({}, rmdirDefaults, options);
};
exports.getRmdirOptions = getRmdirOptions;
const getRmOpts = optsGenerator(exports.optsDefaults);
exports.getRmOptsAndCb = optsAndCbGenerator(getRmOpts);
const readFileOptsDefaults = {
flag: 'r',
};
exports.getReadFileOptions = optsGenerator(readFileOptsDefaults);
const readdirDefaults = {
encoding: 'utf8',
recursive: false,
withFileTypes: false,
};
exports.getReaddirOptions = optsGenerator(readdirDefaults);
exports.getReaddirOptsAndCb = optsAndCbGenerator(exports.getReaddirOptions);
const opendirDefaults = {
encoding: 'utf8',
bufferSize: 32,
recursive: false,
};
exports.getOpendirOptions = optsGenerator(opendirDefaults);
exports.getOpendirOptsAndCb = optsAndCbGenerator(exports.getOpendirOptions);
const appendFileDefaults = {
encoding: 'utf8',
mode: 438 /* MODE.DEFAULT */,
flag: fs_node_utils_1.FLAGS[fs_node_utils_1.FLAGS.a],
};
exports.getAppendFileOpts = optsGenerator(appendFileDefaults);
exports.getAppendFileOptsAndCb = optsAndCbGenerator(exports.getAppendFileOpts);
const statDefaults = {
bigint: false,
};
const getStatOptions = (options = {}) => Object.assign({}, statDefaults, options);
exports.getStatOptions = getStatOptions;
const getStatOptsAndCb = (options, callback) => typeof options === 'function' ? [(0, exports.getStatOptions)(), options] : [(0, exports.getStatOptions)(options), (0, util_1.validateCallback)(callback)];
exports.getStatOptsAndCb = getStatOptsAndCb;
const statfsDefaults = {
bigint: false,
};
const getStatfsOptions = (options = {}) => Object.assign({}, statfsDefaults, options);
exports.getStatfsOptions = getStatfsOptions;
const getStatfsOptsAndCb = (options, callback) => typeof options === 'function'
? [(0, exports.getStatfsOptions)(), options]
: [(0, exports.getStatfsOptions)(options), (0, util_1.validateCallback)(callback)];
exports.getStatfsOptsAndCb = getStatfsOptsAndCb;
const realpathDefaults = exports.optsDefaults;
exports.getRealpathOptions = optsGenerator(realpathDefaults);
exports.getRealpathOptsAndCb = optsAndCbGenerator(exports.getRealpathOptions);
exports.writeFileDefaults = {
encoding: 'utf8',
mode: 438 /* MODE.DEFAULT */,
flag: fs_node_utils_1.FLAGS[fs_node_utils_1.FLAGS.w],
};
exports.getWriteFileOptions = optsGenerator(exports.writeFileDefaults);
//# sourceMappingURL=options.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"options.js","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":";;;AAkBA,gCAoBC;AAED,sCAEC;AAED,gDAGC;AA9CD,8DAAyE;AAEzE,iCAA0C;AAG1C,MAAM,aAAa,GAAuB;IACxC,IAAI,oBAAU;IACd,SAAS,EAAE,KAAK;CACjB,CAAC;AAEK,MAAM,eAAe,GAAG,CAAC,OAAO,EAAsB,EAAE;IAC7D,IAAI,OAAO,OAAO,KAAK,QAAQ;QAAE,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,aAAa,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;IAC5F,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,aAAa,EAAE,OAAO,CAAC,CAAC;AACnD,CAAC,CAAC;AAHW,QAAA,eAAe,mBAG1B;AAEF,MAAM,WAAW,GAAG,MAAM,CAAC,EAAE,CAAC,gEAAgE,MAAM,UAAU,CAAC;AAE/G,SAAgB,UAAU,CAA0B,QAAW,EAAE,OAAoB;IACnF,IAAI,IAAO,CAAC;IACZ,IAAI,CAAC,OAAO;QAAE,OAAO,QAAQ,CAAC;SACzB,CAAC;QACJ,MAAM,MAAM,GAAG,OAAO,OAAO,CAAC;QAC9B,QAAQ,MAAM,EAAE,CAAC;YACf,KAAK,QAAQ;gBACX,IAAI,GAAG,MAAM,CAAC,MAAM,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CommonObjects {
F_OK: number;
R_OK: number;
W_OK: number;
X_OK: number;
constants: typeof constants;
Dir: new (...args: unknown[]) => misc.IDir;
Dirent: new (...args: unknown[]) => misc.IDirent;
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;
}
+3
View File
@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=FsCommonObjects.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"FsCommonObjects.js","sourceRoot":"","sources":["../../src/types/FsCommonObjects.ts"],"names":[],"mappings":""}
+41
View File
@@ -0,0 +1,41 @@
import type { constants } from '@jsonjoy.com/fs-node-utils';
import type * as opts from '@jsonjoy.com/fs-node-utils/lib/types/options';
import * as misc from './misc';
export interface FsPromisesApi {
constants: typeof constants;
FileHandle: new (...args: unknown[]) => misc.IFileHandle;
access: (path: misc.PathLike, mode?: number) => Promise<void>;
appendFile: (path: misc.TFileHandle, data: misc.TData, options?: opts.IAppendFileOptions | string) => Promise<void>;
chmod: (path: misc.PathLike, mode: misc.TMode) => Promise<void>;
chown: (path: misc.PathLike, uid: number, gid: number) => Promise<void>;
copyFile: (src: misc.PathLike, dest: misc.PathLike, flags?: misc.TFlagsCopy) => Promise<void>;
cp: (src: string | URL, dest: string | URL, options?: opts.ICpOptions) => Promise<void>;
lchmod: (path: misc.PathLike, mode: misc.TMode) => Promise<void>;
lchown: (path: misc.PathLike, uid: number, gid: number) => Promise<void>;
lutimes: (path: misc.PathLike, atime: misc.TTime, mtime: misc.TTime) => Promise<void>;
link: (existingPath: misc.PathLike, newPath: misc.PathLike) => Promise<void>;
lstat: (path: misc.PathLike, options?: opts.IStatOptions) => Promise<misc.IStats>;
mkdir: (path: misc.PathLike, options?: misc.TMode | opts.IMkdirOptions) => Promise<string | undefined>;
mkdtemp: (prefix: string, options?: opts.IOptions) => Promise<misc.TDataOut>;
open: (path: misc.PathLike, flags?: misc.TFlags, mode?: misc.TMode) => Promise<misc.IFileHandle>;
opendir: (path: misc.PathLike, options?: opts.IOpendirOptions) => Promise<misc.IDir>;
readdir: (path: misc.PathLike, options?: opts.IReaddirOptions | string) => Promise<misc.TDataOut[] | misc.IDirent[]>;
readFile: (id: misc.TFileHandle, options?: opts.IReadFileOptions | string) => Promise<misc.TDataOut>;
readlink: (path: misc.PathLike, options?: opts.IOptions) => Promise<misc.TDataOut>;
realpath: (path: misc.PathLike, options?: opts.IRealpathOptions | string) => Promise<misc.TDataOut>;
rename: (oldPath: misc.PathLike, newPath: misc.PathLike) => Promise<void>;
rmdir: (path: misc.PathLike, options?: opts.IRmdirOptions) => Promise<void>;
rm: (path: misc.PathLike, options?: opts.IRmOptions) => Promise<void>;
stat: (path: misc.PathLike, options?: opts.IStatOptions) => Promise<misc.IStats>;
statfs: (path: misc.PathLike, options?: opts.IStatOptions) => Promise<misc.IStatFs>;
symlink: (target: misc.PathLike, path: misc.PathLike, type?: misc.symlink.Type) => Promise<void>;
truncate: (path: misc.PathLike, len?: number) => Promise<void>;
unlink: (path: misc.PathLike) => Promise<void>;
utimes: (path: misc.PathLike, atime: misc.TTime, mtime: misc.TTime) => Promise<void>;
watch: (filename: misc.PathLike, options?: opts.IWatchOptions) => AsyncIterableIterator<{
eventType: string;
filename: string | Buffer;
}>;
writeFile: (id: misc.TFileHandle, data: misc.TPromisesData, options?: opts.IWriteFileOptions) => Promise<void>;
glob: (pattern: string, options?: opts.IGlobOptions) => Promise<string[]>;
}
+3
View File
@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=FsPromisesApi.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"FsPromisesApi.js","sourceRoot":"","sources":["../../src/types/FsPromisesApi.ts"],"names":[],"mappings":""}
+157
View File
@@ -0,0 +1,157 @@
import type { PathLike as NodePathLike, symlink } from '@jsonjoy.com/fs-node-builtins/lib/fs';
import type { constants } from '@jsonjoy.com/fs-node-utils';
import type { EventEmitter } from '@jsonjoy.com/fs-node-builtins/lib/events';
import type { TSetTimeout } from '@jsonjoy.com/fs-node-utils/lib/setTimeoutUnref';
import type { IAppendFileOptions, IFileHandleReadStreamOptions, IFileHandleWriteStreamOptions, IReadableWebStreamOptions, IReadFileOptions, IStatOptions, IWriteFileOptions } from '@jsonjoy.com/fs-node-utils/lib/types/options';
import type { Readable, Writable } from '@jsonjoy.com/fs-node-builtins/lib/stream';
export { symlink };
export type PathLike = NodePathLike | Uint8Array;
export type TDataOut = string | Buffer;
export type TEncodingExtended = BufferEncoding | 'buffer';
export type TFileId = PathLike | number;
export type TData = TDataOut | ArrayBufferView | DataView;
export type TPromisesData = TData | Readable;
export type TFlags = string | number;
export type TMode = string | number;
export type TTime = number | string | Date;
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 {
code?: string;
}
export type TFlagsCopy = typeof constants.COPYFILE_EXCL | typeof constants.COPYFILE_FICLONE | typeof constants.COPYFILE_FICLONE_FORCE;
export type TStatNumber = number | bigint;
export interface IStats<T = TStatNumber> {
uid: T;
gid: T;
rdev: T;
blksize: T;
ino: T;
size: T;
blocks: T;
atime: Date;
mtime: Date;
ctime: Date;
birthtime: Date;
atimeMs: T;
mtimeMs: T;
ctimeMs: T;
birthtimeMs: T;
dev: T;
mode: T;
nlink: T;
isDirectory(): boolean;
isFile(): boolean;
isBlockDevice(): boolean;
isCharacterDevice(): boolean;
isSymbolicLink(): boolean;
isFIFO(): boolean;
isSocket(): boolean;
}
export interface IStatFs<T = TStatNumber> {
bavail: T;
bfree: T;
blocks: T;
bsize: T;
ffree: T;
files: T;
type: T;
}
export interface IDir extends Disposable, AsyncDisposable {
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 {
name: TDataOut;
/**
* @deprecated
* @see https://nodejs.org/api/deprecations.html#DEP0178
*/
parent?: string;
parentPath: string;
isDirectory(): boolean;
isFile(): boolean;
isBlockDevice(): boolean;
isCharacterDevice(): boolean;
isSymbolicLink(): boolean;
isFIFO(): boolean;
isSocket(): boolean;
}
export interface IStatWatcher extends EventEmitter {
filename: string;
interval: number;
timeoutRef?: any;
setTimeout: TSetTimeout;
prev: IStats;
start(path: string, persistent?: boolean, interval?: number): void;
stop(): void;
}
export interface IReadStream extends Readable {
bytesRead: number;
path: string | Buffer;
pending: boolean;
}
export interface IWriteStream extends Writable {
bytesWritten: number;
path: string;
pending: boolean;
close(callback?: (err?: Error) => void): void;
}
export interface IFSWatcher extends EventEmitter {
start(path: PathLike, persistent?: boolean, recursive?: boolean, encoding?: BufferEncoding): void;
close(): void;
}
/**
* Declare ReadableStream in case dom.d.ts is not added to the tsconfig lib causing
* ReadableStream interface is not defined. For developers with dom.d.ts added,
* the ReadableStream interface will be merged correctly.
*/
declare global {
export interface ReadableStream {
}
}
export interface IFileHandle extends EventEmitter {
fd: number;
getAsyncId(): number;
appendFile(data: TData, options?: IAppendFileOptions | string): Promise<void>;
chmod(mode: TMode): Promise<void>;
chown(uid: number, gid: number): Promise<void>;
close(): Promise<void>;
createReadStream(options: IFileHandleReadStreamOptions): IReadStream;
createWriteStream(options: IFileHandleWriteStreamOptions): IWriteStream;
datasync(): Promise<void>;
readableWebStream(options?: IReadableWebStreamOptions): ReadableStream;
read(buffer: Buffer | Uint8Array, offset: number, length: number, position?: number | null): Promise<TFileHandleReadResult>;
readv(buffers: ArrayBufferView[], position?: number | null): Promise<TFileHandleReadvResult>;
readFile(options?: IReadFileOptions | string): Promise<TDataOut>;
stat(options?: IStatOptions): Promise<IStats>;
truncate(len?: number): Promise<void>;
utimes(atime: TTime, mtime: TTime): Promise<void>;
write(buffer: Buffer | ArrayBufferView | DataView, offset?: number, length?: number, position?: number | null): Promise<TFileHandleWriteResult>;
writev(buffers: ArrayBufferView[], position?: number | null): Promise<TFileHandleWritevResult>;
writeFile(data: TData, options?: IWriteFileOptions): Promise<void>;
}
export type TFileHandle = PathLike | IFileHandle;
export interface TFileHandleReadResult {
bytesRead: number;
buffer: Buffer | Uint8Array;
}
export interface TFileHandleWriteResult {
bytesWritten: number;
buffer: Buffer | Uint8Array;
}
export interface TFileHandleReadvResult {
bytesRead: number;
buffers: ArrayBufferView[];
}
export interface TFileHandleWritevResult {
bytesWritten: number;
buffers: ArrayBufferView[];
}
export type AssertCallback<T> = T extends () => void ? T : never;
+3
View File
@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=misc.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"misc.js","sourceRoot":"","sources":["../../src/types/misc.ts"],"names":[],"mappings":""}
+21
View File
@@ -0,0 +1,21 @@
import { TEncodingExtended } from '@jsonjoy.com/fs-node-utils';
import { Buffer } from '@jsonjoy.com/fs-node-builtins/lib/internal/buffer';
import { Readable } from '@jsonjoy.com/fs-node-builtins/lib/stream';
import { StatError } from '@jsonjoy.com/fs-core';
import type { FsCallbackApi } from '@jsonjoy.com/fs-node-utils';
import type * as misc from '@jsonjoy.com/fs-node-utils/lib/types/misc';
export declare function promisify(fs: FsCallbackApi, fn: string, getResult?: (result: any) => any): (...args: any[]) => Promise<any>;
export declare function validateCallback<T>(callback: T): misc.AssertCallback<T>;
export declare function modeToNumber(mode: misc.TMode | undefined, def?: any): number;
export declare function nullCheck(path: any, callback?: any): boolean;
export declare function pathToFilename(path: misc.PathLike): string;
export declare function createError(errorCode: string, func?: string, path?: string, path2?: string, Constructor?: ErrorConstructor): Error;
export declare function createStatError(errorCode: string, func?: string, path?: string, path2?: string): StatError;
export declare function genRndStr6(): string;
export declare function flagsToNumber(flags: misc.TFlags | undefined): number;
export declare function streamToBuffer(stream: Readable): Promise<Buffer<ArrayBufferLike>>;
export declare const bufToUint8: (buf: Buffer) => Uint8Array;
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 | null) => [fd: number, buf: Buffer, offset: number, length?: number, position?: number | null];
export declare function bufferToEncoding(buffer: Buffer, encoding?: TEncodingExtended): misc.TDataOut;
export declare function isReadableStream(stream: any): stream is Readable;
+296
View File
@@ -0,0 +1,296 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getWriteSyncArgs = exports.getWriteArgs = exports.bufToUint8 = void 0;
exports.promisify = promisify;
exports.validateCallback = validateCallback;
exports.modeToNumber = modeToNumber;
exports.nullCheck = nullCheck;
exports.pathToFilename = pathToFilename;
exports.createError = createError;
exports.createStatError = createStatError;
exports.genRndStr6 = genRndStr6;
exports.flagsToNumber = flagsToNumber;
exports.streamToBuffer = streamToBuffer;
exports.bufferToEncoding = bufferToEncoding;
exports.isReadableStream = isReadableStream;
const fs_node_utils_1 = require("@jsonjoy.com/fs-node-utils");
const errors = require("@jsonjoy.com/fs-node-builtins/lib/internal/errors");
const buffer_1 = require("@jsonjoy.com/fs-node-builtins/lib/internal/buffer");
const fs_core_1 = require("@jsonjoy.com/fs-core");
function promisify(fs, fn, getResult = input => input) {
return (...args) => new Promise((resolve, reject) => {
fs[fn].bind(fs)(...args, (error, result) => {
if (error)
return reject(error);
return resolve(getResult(result));
});
});
}
function validateCallback(callback) {
if (typeof callback !== 'function')
throw TypeError(fs_node_utils_1.ERRSTR.CB);
return callback;
}
function _modeToNumber(mode, def) {
if (typeof mode === 'number')
return mode;
if (typeof mode === 'string')
return parseInt(mode, 8);
if (def)
return modeToNumber(def);
return undefined;
}
function modeToNumber(mode, def) {
const result = _modeToNumber(mode, def);
if (typeof result !== 'number' || isNaN(result))
throw new TypeError(fs_node_utils_1.ERRSTR.MODE_INT);
return result;
}
function nullCheck(path, callback) {
if (('' + path).indexOf('\u0000') !== -1) {
const er = new Error('Path must be a string without null bytes');
er.code = 'ENOENT';
if (typeof callback !== 'function')
throw er;
queueMicrotask(() => {
callback(er);
});
return false;
}
return true;
}
function getPathFromURLPosix(url) {
if (url.hostname !== '') {
throw new errors.TypeError('ERR_INVALID_FILE_URL_HOST', process.platform);
}
const pathname = url.pathname;
for (let n = 0; n < pathname.length; n++) {
if (pathname[n] === '%') {
const third = pathname.codePointAt(n + 2) | 0x20;
if (pathname[n + 1] === '2' && third === 102) {
throw new errors.TypeError('ERR_INVALID_FILE_URL_PATH', 'must not include encoded / characters');
}
}
}
return decodeURIComponent(pathname);
}
function pathToFilename(path) {
if (path instanceof Uint8Array) {
path = (0, buffer_1.bufferFrom)(path);
}
if (typeof path !== 'string' && !buffer_1.Buffer.isBuffer(path)) {
try {
if (!(path instanceof require('url').URL))
throw new TypeError(fs_node_utils_1.ERRSTR.PATH_STR);
}
catch (err) {
throw new TypeError(fs_node_utils_1.ERRSTR.PATH_STR);
}
path = getPathFromURLPosix(path);
}
const pathString = String(path);
nullCheck(pathString);
// return slash(pathString);
return pathString;
}
const ENOENT = 'ENOENT';
const EBADF = 'EBADF';
const EINVAL = 'EINVAL';
const EPERM = 'EPERM';
const EPROTO = 'EPROTO';
const EEXIST = 'EEXIST';
const ENOTDIR = 'ENOTDIR';
const EMFILE = 'EMFILE';
const EACCES = 'EACCES';
const EISDIR = 'EISDIR';
const ENOTEMPTY = 'ENOTEMPTY';
const ENOSYS = 'ENOSYS';
const ERR_FS_EISDIR = 'ERR_FS_EISDIR';
const ERR_OUT_OF_RANGE = 'ERR_OUT_OF_RANGE';
function formatError(errorCode, func = '', path = '', path2 = '') {
let pathFormatted = '';
if (path)
pathFormatted = ` '${path}'`;
if (path2)
pathFormatted += ` -> '${path2}'`;
switch (errorCode) {
case ENOENT:
return `ENOENT: no such file or directory, ${func}${pathFormatted}`;
case EBADF:
return `EBADF: bad file descriptor, ${func}${pathFormatted}`;
case EINVAL:
return `EINVAL: invalid argument, ${func}${pathFormatted}`;
case EPERM:
return `EPERM: operation not permitted, ${func}${pathFormatted}`;
case EPROTO:
return `EPROTO: protocol error, ${func}${pathFormatted}`;
case EEXIST:
return `EEXIST: file already exists, ${func}${pathFormatted}`;
case ENOTDIR:
return `ENOTDIR: not a directory, ${func}${pathFormatted}`;
case EISDIR:
return `EISDIR: illegal operation on a directory, ${func}${pathFormatted}`;
case EACCES:
return `EACCES: permission denied, ${func}${pathFormatted}`;
case ENOTEMPTY:
return `ENOTEMPTY: directory not empty, ${func}${pathFormatted}`;
case EMFILE:
return `EMFILE: too many open files, ${func}${pathFormatted}`;
case ENOSYS:
return `ENOSYS: function not implemented, ${func}${pathFormatted}`;
case ERR_FS_EISDIR:
return `[ERR_FS_EISDIR]: Path is a directory: ${func} returned EISDIR (is a directory) ${path}`;
case ERR_OUT_OF_RANGE:
return `[ERR_OUT_OF_RANGE]: value out of range, ${func}${pathFormatted}`;
default:
return `${errorCode}: error occurred, ${func}${pathFormatted}`;
}
}
function createError(errorCode, func = '', path = '', path2 = '', Constructor = Error) {
const error = new Constructor(formatError(errorCode, func, path, path2));
error.code = errorCode;
if (path) {
error.path = path;
}
return error;
}
function createStatError(errorCode, func = '', path = '', path2 = '') {
return {
code: errorCode,
message: formatError(errorCode, func, path, path2),
path,
toError() {
const error = new Error(this.message);
error.code = this.code;
if (this.path) {
error.path = this.path;
}
return error;
},
};
}
function genRndStr6() {
return Math.random().toString(36).slice(2, 8).padEnd(6, '0');
}
function flagsToNumber(flags) {
if (typeof flags === 'number')
return flags;
if (typeof flags === 'string') {
const flagsNum = fs_node_utils_1.FLAGS[flags];
if (typeof flagsNum !== 'undefined')
return flagsNum;
}
// throw new TypeError(formatError(ERRSTR_FLAG(flags)));
throw new errors.TypeError('ERR_INVALID_OPT_VALUE', 'flags', flags);
}
function streamToBuffer(stream) {
const chunks = [];
return new Promise((resolve, reject) => {
stream.on('data', chunk => chunks.push(chunk));
stream.on('end', () => resolve(buffer_1.Buffer.concat(chunks)));
stream.on('error', reject);
});
}
const bufToUint8 = (buf) => new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
exports.bufToUint8 = bufToUint8;
const getWriteArgs = (fd, a, b, c, d, e) => {
(0, fs_core_1.validateFd)(fd);
let offset = 0;
let length;
let position = null;
let encoding;
let callback;
const tipa = typeof a;
const tipb = typeof b;
const tipc = typeof c;
const tipd = typeof d;
if (tipa !== 'string') {
if (tipb === 'function') {
callback = b;
}
else if (tipc === 'function') {
offset = b | 0;
callback = c;
}
else if (tipd === 'function') {
offset = b | 0;
length = c;
callback = d;
}
else {
offset = b | 0;
length = c;
position = d;
callback = e;
}
}
else {
if (tipb === 'function') {
callback = b;
}
else if (tipc === 'function') {
position = b;
callback = c;
}
else if (tipd === 'function') {
position = b;
encoding = c;
callback = d;
}
}
const buf = (0, fs_core_1.dataToBuffer)(a, encoding);
if (tipa !== 'string') {
if (typeof length === 'undefined')
length = buf.length;
}
else {
offset = 0;
length = buf.length;
}
const cb = validateCallback(callback);
return [fd, tipa === 'string', buf, offset, length, position, cb];
};
exports.getWriteArgs = getWriteArgs;
const getWriteSyncArgs = (fd, a, b, c, d) => {
(0, fs_core_1.validateFd)(fd);
let encoding;
let offset;
let length;
let position;
const isBuffer = typeof a !== 'string';
if (isBuffer) {
offset = (b || 0) | 0;
length = c;
position = d;
}
else {
position = b;
encoding = c;
}
const buf = (0, fs_core_1.dataToBuffer)(a, encoding);
if (isBuffer) {
if (typeof length === 'undefined') {
length = buf.length;
}
}
else {
offset = 0;
length = buf.length;
}
return [fd, buf, offset || 0, length, position];
};
exports.getWriteSyncArgs = getWriteSyncArgs;
function bufferToEncoding(buffer, encoding) {
if (!encoding || encoding === 'buffer')
return buffer;
else
return buffer.toString(encoding);
}
function isReadableStream(stream) {
return (stream !== null &&
typeof stream === 'object' &&
typeof stream.pipe === 'function' &&
typeof stream.on === 'function' &&
stream.readable === true);
}
//# sourceMappingURL=util.js.map
File diff suppressed because one or more lines are too long
+404
View File
@@ -0,0 +1,404 @@
import { FanOutUnsubscribe } from 'thingies/lib/fanout';
import { Link, Superblock, DirectoryJSON, NestedDirectoryJSON, TFileId, type IProcess } from '@jsonjoy.com/fs-core';
import Stats from './Stats';
import Dirent from './Dirent';
import StatFs from './StatFs';
import { Buffer } from '@jsonjoy.com/fs-node-builtins/lib/internal/buffer';
import { TSetTimeout } from '@jsonjoy.com/fs-node-utils/lib/setTimeoutUnref';
import { Writable } from '@jsonjoy.com/fs-node-builtins/lib/stream';
import { constants, TDataOut } from '@jsonjoy.com/fs-node-utils';
import { EventEmitter } from '@jsonjoy.com/fs-node-builtins/lib/events';
import * as misc from '@jsonjoy.com/fs-node-utils/lib/types/misc';
import * as opts from '@jsonjoy.com/fs-node-utils/lib/types/options';
import { FsCallbackApi, WritevCallback } from '@jsonjoy.com/fs-node-utils/lib/types/FsCallbackApi';
import { ToTreeOptions } from '@jsonjoy.com/fs-print';
import * as fsSnapshot from '@jsonjoy.com/fs-snapshot';
import type { PathLike, symlink } from '@jsonjoy.com/fs-node-utils/lib/types/misc';
import type { FsPromisesApi, FsSynchronousApi } from '@jsonjoy.com/fs-node-utils';
import { Dir } from './Dir';
export type { SnapshotNode } from '@jsonjoy.com/fs-snapshot';
export interface IError extends Error {
code?: string;
}
export type TData = TDataOut | ArrayBufferView | DataView;
export type TFlags = string | number;
export type TMode = string | number;
export type TTime = number | string | Date;
export type TFlagsCopy = typeof constants.COPYFILE_EXCL | typeof constants.COPYFILE_FICLONE | typeof constants.COPYFILE_FICLONE_FORCE;
export interface IAppendFileOptions extends opts.IFileOptions {
}
export interface IWatchFileOptions {
persistent?: boolean;
interval?: number;
}
export interface IWatchOptions extends opts.IOptions {
persistent?: boolean;
recursive?: boolean;
}
export declare function pathToSteps(path: PathLike): string[];
export declare function dataToStr(data: TData, encoding?: BufferEncoding): string;
export declare function toUnixTimestamp(time: any): any;
/**
* `Volume` represents a file system.
*/
export declare class Volume implements FsCallbackApi, FsSynchronousApi {
readonly _core: Superblock;
static readonly fromJSON: (json: DirectoryJSON, cwd?: string, opts?: {
process?: IProcess;
}) => Volume;
static readonly fromNestedJSON: (json: NestedDirectoryJSON, cwd?: string, opts?: {
process?: IProcess;
}) => Volume;
StatWatcher: new () => StatWatcher;
ReadStream: new (...args: any[]) => misc.IReadStream;
WriteStream: new (...args: any[]) => IWriteStream;
FSWatcher: new () => FSWatcher;
realpath: {
(path: PathLike, callback: misc.TCallback<TDataOut>): void;
(path: PathLike, options: opts.IRealpathOptions | string, callback: misc.TCallback<TDataOut>): void;
native: {
(path: PathLike, callback: misc.TCallback<TDataOut>): void;
(path: PathLike, options: opts.IRealpathOptions | string, callback: misc.TCallback<TDataOut>): void;
};
};
realpathSync: {
(path: PathLike, options?: opts.IRealpathOptions | string): TDataOut;
native: (path: PathLike, options?: opts.IRealpathOptions | string) => TDataOut;
};
private promisesApi;
get promises(): FsPromisesApi;
constructor(_core?: Superblock);
private wrapAsync;
reset(): void;
toJSON(paths?: PathLike | PathLike[], json?: {}, isRelative?: boolean, asBuffer?: boolean): DirectoryJSON<string | null>;
fromJSON(json: DirectoryJSON, cwd?: string): void;
fromNestedJSON(json: NestedDirectoryJSON, cwd?: string): void;
mountSync(mountpoint: string, json: DirectoryJSON): void;
openSync: (path: PathLike, flags: TFlags, mode?: TMode) => number;
open: {
(path: PathLike, flags: TFlags, /* ... */ callback: misc.TCallback<number>): void;
(path: PathLike, flags: TFlags, mode: TMode, callback: misc.TCallback<number>): void;
};
closeSync: (fd: number) => void;
close: (fd: number, callback: misc.TCallback<void>) => void;
readSync: (fd: number, buffer: Buffer | ArrayBufferView | DataView, offset: number, length: number, position: number | null) => number;
read: (fd: number, buffer: Buffer | ArrayBufferView | DataView, offset: number, length: number, position: number | null, callback: (err?: Error | null, bytesRead?: number, buffer?: Buffer | ArrayBufferView | DataView) => void) => void;
readv: {
(fd: number, buffers: ArrayBufferView[], callback: misc.TCallback2<number, ArrayBufferView[]>): void;
(fd: number, buffers: ArrayBufferView[], position: number | null, callback: misc.TCallback2<number, ArrayBufferView[]>): void;
};
readvSync: (fd: number, buffers: ArrayBufferView[], position?: number | null) => number;
private readonly _readfile;
readFileSync: (file: TFileId, options?: opts.IReadFileOptions | string) => TDataOut;
readFile: {
(id: TFileId, callback: misc.TCallback<TDataOut>): any;
(id: TFileId, options: opts.IReadFileOptions | string, callback: misc.TCallback<TDataOut>): any;
};
private _write;
writeSync: {
(fd: number, buffer: Buffer | ArrayBufferView | DataView, offset?: number, length?: number, position?: number | null): number;
(fd: number, str: string, position?: number, encoding?: BufferEncoding): number;
};
write: {
(fd: number, buffer: Buffer | ArrayBufferView | DataView, callback: (...args: any[]) => void): any;
(fd: number, buffer: Buffer | ArrayBufferView | DataView, offset: number, callback: (...args: any[]) => void): any;
(fd: number, buffer: Buffer | ArrayBufferView | DataView, offset: number, length: number, callback: (...args: any[]) => void): any;
(fd: number, buffer: Buffer | ArrayBufferView | DataView, offset: number, length: number, position: number, callback: (...args: any[]) => void): any;
(fd: number, str: string, callback: (...args: any[]) => void): any;
(fd: number, str: string, position: number, callback: (...args: any[]) => void): any;
(fd: number, str: string, position: number, encoding: BufferEncoding, callback: (...args: any[]) => void): any;
};
private writevBase;
writev: {
(fd: number, buffers: ArrayBufferView[], callback: WritevCallback): void;
(fd: number, buffers: ArrayBufferView[], position: number | null, callback: WritevCallback): void;
};
writevSync: (fd: number, buffers: ArrayBufferView[], position?: number | null) => number;
writeFileSync: (id: TFileId, data: TData, options?: opts.IWriteFileOptions) => void;
writeFile: {
(id: TFileId, data: TData, callback: misc.TCallback<void>): void;
(id: TFileId, data: TData, options: opts.IWriteFileOptions | string, callback: misc.TCallback<void>): void;
};
private _copyFile;
copyFileSync: (src: PathLike, dest: PathLike, flags?: TFlagsCopy) => void;
copyFile: {
(src: PathLike, dest: PathLike, callback: misc.TCallback<void>): any;
(src: PathLike, dest: PathLike, flags: TFlagsCopy, callback: misc.TCallback<void>): any;
};
private readonly _cp;
private isSrcSubdir;
private cpFileSync;
private cpDirSync;
private cpSymlinkSync;
linkSync: (existingPath: PathLike, newPath: PathLike) => void;
link: (existingPath: PathLike, newPath: PathLike, callback: misc.TCallback<void>) => void;
unlinkSync: (path: PathLike) => void;
unlink: (path: PathLike, callback: misc.TCallback<void>) => void;
/**
* `type` argument works only on Windows.
* @param target
* @param path
* @param type
*/
symlinkSync: (target: PathLike, path: PathLike, type?: symlink.Type) => void;
symlink: {
(target: PathLike, path: PathLike, callback: misc.TCallback<void>): any;
(target: PathLike, path: PathLike, type: symlink.Type, callback: misc.TCallback<void>): any;
};
private readonly _lstat;
lstatSync: {
(path: PathLike): Stats<number>;
(path: PathLike, options: {
throwIfNoEntry?: true | undefined;
}): Stats<number>;
(path: PathLike, options: {
bigint: false;
throwIfNoEntry?: true | undefined;
}): Stats<number>;
(path: PathLike, options: {
bigint: true;
throwIfNoEntry?: true | undefined;
}): Stats<bigint>;
(path: PathLike, options: {
throwIfNoEntry: false;
}): Stats<number> | undefined;
(path: PathLike, options: {
bigint: false;
throwIfNoEntry: false;
}): Stats<number> | undefined;
(path: PathLike, options: {
bigint: true;
throwIfNoEntry: false;
}): Stats<bigint> | undefined;
};
lstat(path: PathLike, callback: misc.TCallback<Stats>): void;
lstat(path: PathLike, options: opts.IStatOptions, callback: misc.TCallback<Stats>): void;
private _stat;
private _statOrThrow;
statSync(path: PathLike): Stats<number>;
statSync(path: PathLike, options: {
throwIfNoEntry?: true;
}): Stats<number>;
statSync(path: PathLike, options: {
throwIfNoEntry: false;
}): Stats<number> | undefined;
statSync(path: PathLike, options: {
bigint: false;
throwIfNoEntry?: true;
}): Stats<number>;
statSync(path: PathLike, options: {
bigint: true;
throwIfNoEntry?: true;
}): Stats<bigint>;
statSync(path: PathLike, options: {
bigint: false;
throwIfNoEntry: false;
}): Stats<number> | undefined;
statSync(path: PathLike, options: {
bigint: true;
throwIfNoEntry: false;
}): Stats<bigint> | undefined;
stat(path: PathLike, callback: misc.TCallback<Stats>): void;
stat(path: PathLike, options: opts.IStatOptions, callback: misc.TCallback<Stats>): void;
private fstatBase;
fstatSync(fd: number): Stats<number>;
fstatSync(fd: number, options: {
bigint: false;
}): Stats<number>;
fstatSync(fd: number, options: {
bigint: true;
}): Stats<bigint>;
fstat(fd: number, callback: misc.TCallback<Stats>): void;
fstat(fd: number, options: opts.IFStatOptions, callback: misc.TCallback<Stats>): void;
renameSync: (oldPath: PathLike, newPath: PathLike) => void;
rename: (oldPath: PathLike, newPath: PathLike, callback: misc.TCallback<void>) => void;
private _exists;
existsSync: (path: PathLike) => boolean;
exists: (path: PathLike, callback: (exists: boolean) => void) => void;
private _access;
accessSync: (path: PathLike, mode?: number) => void;
access: {
(path: PathLike, callback: misc.TCallback<void>): any;
(path: PathLike, mode: number, callback: misc.TCallback<void>): any;
};
appendFileSync: (id: TFileId, data: TData, options?: IAppendFileOptions | string) => void;
appendFile: {
(id: TFileId, data: TData, callback: misc.TCallback<void>): any;
(id: TFileId, data: TData, options: IAppendFileOptions | string, callback: misc.TCallback<void>): any;
};
private readonly _readdir;
readdirSync: (path: PathLike, options?: opts.IReaddirOptions | string) => TDataOut[] | Dirent[];
readdir: {
(path: PathLike, callback: misc.TCallback<TDataOut[] | Dirent[]>): any;
(path: PathLike, options: opts.IReaddirOptions | string, callback: misc.TCallback<TDataOut[] | Dirent[]>): any;
};
private readonly _readlink;
readlinkSync: (path: PathLike, options?: opts.IOptions) => TDataOut;
readlink: {
(path: PathLike, callback: misc.TCallback<TDataOut>): any;
(path: PathLike, options: opts.IOptions, callback: misc.TCallback<TDataOut>): any;
};
private readonly _fsync;
fsyncSync: (fd: number) => void;
fsync: (fd: number, callback: misc.TCallback<void>) => void;
private readonly _fdatasync;
fdatasyncSync: (fd: number) => void;
fdatasync: (fd: number, callback: misc.TCallback<void>) => void;
private readonly _ftruncate;
ftruncateSync: (fd: number, len?: number) => void;
ftruncate: {
(fd: number, callback: misc.TCallback<void>): any;
(fd: number, len: number, callback: misc.TCallback<void>): any;
};
private readonly _truncate;
/**
* `id` should be a file descriptor or a path. `id` as file descriptor will
* not be supported soon.
*/
truncateSync: (id: TFileId, len?: number) => void;
truncate: {
(id: TFileId, callback: misc.TCallback<void>): any;
(id: TFileId, len: number, callback: misc.TCallback<void>): any;
};
private readonly _futimes;
futimesSync: (fd: number, atime: TTime, mtime: TTime) => void;
futimes: (fd: number, atime: TTime, mtime: TTime, callback: misc.TCallback<void>) => void;
private readonly _utimes;
utimesSync: (path: PathLike, atime: TTime, mtime: TTime) => void;
utimes: (path: PathLike, atime: TTime, mtime: TTime, callback: misc.TCallback<void>) => void;
lutimesSync: (path: PathLike, atime: TTime, mtime: TTime) => void;
lutimes: (path: PathLike, atime: TTime, mtime: TTime, callback: misc.TCallback<void>) => void;
mkdirSync: {
(path: PathLike, options: opts.IMkdirOptions & {
recursive: true;
}): string | undefined;
(path: PathLike, options?: TMode | (opts.IMkdirOptions & {
recursive?: false;
})): void;
(path: PathLike, options?: TMode | opts.IMkdirOptions): string | undefined;
};
mkdir: {
(path: PathLike, callback: misc.TCallback<void>): any;
(path: PathLike, mode: TMode | (opts.IMkdirOptions & {
recursive?: false;
}), callback: misc.TCallback<void>): any;
(path: PathLike, mode: opts.IMkdirOptions & {
recursive: true;
}, callback: misc.TCallback<string>): any;
(path: PathLike, mode: TMode | opts.IMkdirOptions, callback: misc.TCallback<string>): any;
};
private readonly _mkdtemp;
mkdtempSync: (prefix: string, options?: opts.IOptions) => TDataOut;
mkdtemp: {
(prefix: string, callback: misc.TCallback<string>): any;
(prefix: string, options: opts.IOptions, callback: misc.TCallback<string>): any;
};
rmdirSync: (path: PathLike, options?: opts.IRmdirOptions) => void;
rmdir: {
(path: PathLike, callback: misc.TCallback<void>): any;
(path: PathLike, options: opts.IRmdirOptions, callback: misc.TCallback<void>): any;
};
rmSync: (path: PathLike, options?: opts.IRmOptions) => void;
rm: {
(path: PathLike, callback: misc.TCallback<void>): void;
(path: PathLike, options: opts.IRmOptions, callback: misc.TCallback<void>): void;
};
private readonly _fchmod;
fchmodSync: (fd: number, mode: TMode) => void;
fchmod: (fd: number, mode: TMode, callback: misc.TCallback<void>) => void;
private readonly _chmod;
chmodSync: (path: PathLike, mode: TMode) => void;
chmod: (path: PathLike, mode: TMode, callback: misc.TCallback<void>) => void;
private readonly _lchmod;
lchmodSync: (path: PathLike, mode: TMode) => void;
lchmod: (path: PathLike, mode: TMode, callback: misc.TCallback<void>) => void;
private readonly _fchown;
fchownSync: (fd: number, uid: number, gid: number) => void;
fchown: (fd: number, uid: number, gid: number, callback: misc.TCallback<void>) => void;
private readonly _chown;
chownSync: (path: PathLike, uid: number, gid: number) => void;
chown: (path: PathLike, uid: number, gid: number, callback: misc.TCallback<void>) => void;
private readonly _lchown;
lchownSync: (path: PathLike, uid: number, gid: number) => void;
lchown: (path: PathLike, uid: number, gid: number, callback: misc.TCallback<void>) => void;
private statWatchers;
watchFile(path: PathLike, listener: (curr: Stats, prev: Stats) => void): StatWatcher;
watchFile(path: PathLike, options: IWatchFileOptions, listener: (curr: Stats, prev: Stats) => void): StatWatcher;
unwatchFile(path: PathLike, listener?: (curr: Stats, prev: Stats) => void): void;
createReadStream(path: misc.PathLike, options?: opts.IReadStreamOptions | string): misc.IReadStream;
createWriteStream(path: PathLike, options?: opts.IWriteStreamOptions | string): IWriteStream;
watch(path: PathLike, options?: IWatchOptions | string, listener?: (eventType: string, filename: string) => void): FSWatcher;
cpSync: (src: string | URL, dest: string | URL, options?: opts.ICpOptions) => void;
cp: {
(src: string | URL, dest: string | URL, callback: misc.TCallback<void>): any;
(src: string | URL, dest: string | URL, options: opts.ICpOptions, callback: misc.TCallback<void>): any;
};
private _statfs;
statfsSync(path: PathLike): StatFs<number>;
statfsSync(path: PathLike, options: {
bigint: false;
}): StatFs<number>;
statfsSync(path: PathLike, options: {
bigint: true;
}): StatFs<bigint>;
statfs(path: PathLike, callback: misc.TCallback<StatFs>): void;
statfs(path: PathLike, options: opts.IStafsOptions, callback: misc.TCallback<StatFs>): void;
openAsBlob: (path: PathLike, options?: opts.IOpenAsBlobOptions) => Promise<Blob>;
glob: FsCallbackApi['glob'];
globSync: FsSynchronousApi['globSync'];
private readonly _globSync;
private readonly _opendir;
opendirSync: (path: PathLike, options?: opts.IOpendirOptions | string) => Dir;
opendir: {
(path: PathLike, callback: misc.TCallback<Dir>): any;
(path: PathLike, options: opts.IOpendirOptions | string, callback: misc.TCallback<Dir>): any;
};
toTree(opts?: ToTreeOptions): string;
toSnapshot(path?: string): fsSnapshot.SnapshotNode;
fromSnapshot(snapshot: fsSnapshot.SnapshotNode, path?: string): void;
toBinarySnapshot(path?: string): Uint8Array;
fromBinarySnapshot(binary: Uint8Array, path?: string): void;
toJsonSnapshot(path?: string): string;
fromJsonSnapshot(json: string, path?: string): void;
}
export declare class StatWatcher extends EventEmitter {
vol: Volume;
filename: string;
interval: number;
timeoutRef?: any;
setTimeout: TSetTimeout;
prev: Stats;
constructor(vol: Volume);
private loop;
private hasChanged;
private onInterval;
start(path: string, persistent?: boolean, interval?: number): void;
stop(): void;
}
export interface IWriteStream extends Writable {
bytesWritten: number;
path: string;
pending: boolean;
new (path: PathLike, options: opts.IWriteStreamOptions): any;
open(): any;
close(): any;
}
export declare class FSWatcher extends EventEmitter {
_vol: Volume;
_filename: string;
_steps: string[];
_filenameEncoded: TDataOut;
_recursive: boolean;
_encoding: BufferEncoding;
_link: Link;
_timer: any;
private _listenerRemovers;
constructor(vol: Volume);
private _getName;
private _onParentChild;
private _emit;
private _persist;
start(path: PathLike, persistent?: boolean, recursive?: boolean, encoding?: BufferEncoding): void;
protected _parentChangesUnsub: FanOutUnsubscribe;
close(): void;
}
+1673
View File
File diff suppressed because it is too large Load Diff
File diff suppressed because one or more lines are too long
+89
View File
@@ -0,0 +1,89 @@
{
"name": "@jsonjoy.com/fs-node",
"publishConfig": {
"access": "public"
},
"version": "4.57.1",
"description": "In-memory filesystem with Node.js fs-compatible API",
"author": {
"name": "streamich",
"url": "https://github.com/streamich"
},
"homepage": "https://github.com/streamich/memfs/tree/master/packages/fs-node",
"repository": "streamich/memfs",
"license": "Apache-2.0",
"funding": {
"type": "github",
"url": "https://github.com/sponsors/streamich"
},
"keywords": [
"fs",
"filesystem",
"node",
"virtual",
"memory",
"in-memory",
"memfs"
],
"engines": {
"node": ">=10.0"
},
"main": "lib/index.js",
"types": "lib/index.d.ts",
"typings": "lib/index.d.ts",
"files": [
"LICENSE",
"lib/"
],
"scripts": {
"clean": "rimraf lib typedocs coverage gh-pages yarn-error.log",
"build": "tsc --project tsconfig.build.json --module commonjs --target es2020 --outDir lib",
"jest": "node -r ts-node/register ./node_modules/.bin/jest",
"test": "jest --maxWorkers 7",
"test:ci": "yarn jest --maxWorkers 3 --no-cache",
"coverage": "yarn test --collectCoverage",
"typedoc": "typedoc",
"typecheck": "tsc -p ."
},
"jest": {
"preset": "ts-jest",
"testEnvironment": "node",
"moduleFileExtensions": [
"ts",
"js",
"tsx"
],
"transform": {
"^.+\\.tsx?$": "ts-jest"
},
"transformIgnorePatterns": [
".*/node_modules/.*"
],
"testRegex": ".*/(__tests__|__jest__|demo)/.*\\.(test|spec)\\.tsx?$",
"rootDir": ".",
"testPathIgnorePatterns": [
"node_modules"
]
},
"devDependencies": {
"@types/jest": "^29.0.0",
"@types/node": "^20.0.0",
"jest": "^29.0.0",
"rimraf": "^5.0.0",
"ts-jest": "^29.4.2",
"ts-node": "^10.9.2",
"typescript": "^5.9.2"
},
"peerDependencies": {
"tslib": "2"
},
"dependencies": {
"@jsonjoy.com/fs-core": "4.57.1",
"@jsonjoy.com/fs-node-builtins": "4.57.1",
"@jsonjoy.com/fs-node-utils": "4.57.1",
"@jsonjoy.com/fs-print": "4.57.1",
"@jsonjoy.com/fs-snapshot": "4.57.1",
"glob-to-regex.js": "^1.0.0",
"thingies": "^2.5.0"
}
}