@zenfs/core
Advanced tools
Comparing version 1.1.1 to 1.1.2
@@ -1,2 +0,2 @@ | ||
import type { FileReadResult } from 'fs/promises'; | ||
import type { FileReadResult } from 'node:fs/promises'; | ||
import { InMemoryStore } from './backends/memory.js'; | ||
@@ -3,0 +3,0 @@ import { StoreFS } from './backends/store/fs.js'; |
@@ -1,2 +0,2 @@ | ||
import type { Dir as _Dir, Dirent as _Dirent } from 'fs'; | ||
import type { Dir as _Dir, Dirent as _Dirent } from 'node:fs'; | ||
import type { Stats } from '../stats.js'; | ||
@@ -3,0 +3,0 @@ import type { Callback } from '../utils.js'; |
import { Buffer } from 'buffer'; | ||
import type * as fs from 'node:fs'; | ||
import type * as promises from 'node:fs/promises'; | ||
import type { CreateReadStreamOptions, CreateWriteStreamOptions, FileChangeInfo, FileReadResult, FlagAndOpenMode } from 'node:fs/promises'; | ||
import type { Stream } from 'node:stream'; | ||
@@ -63,3 +62,3 @@ import type { ReadableStream as TReadableStream } from 'node:stream/web'; | ||
*/ | ||
appendFile(data: string | Uint8Array, _options?: (fs.ObjectEncodingOptions & FlagAndOpenMode) | BufferEncoding): Promise<void>; | ||
appendFile(data: string | Uint8Array, _options?: (fs.ObjectEncodingOptions & promises.FlagAndOpenMode) | BufferEncoding): Promise<void>; | ||
/** | ||
@@ -73,3 +72,3 @@ * Asynchronously reads data from the file. | ||
*/ | ||
read<TBuffer extends NodeJS.ArrayBufferView>(buffer: TBuffer, offset?: number, length?: number, position?: number | null): Promise<FileReadResult<TBuffer>>; | ||
read<TBuffer extends NodeJS.ArrayBufferView>(buffer: TBuffer, offset?: number, length?: number, position?: number | null): Promise<promises.FileReadResult<TBuffer>>; | ||
/** | ||
@@ -84,3 +83,3 @@ * Asynchronously reads the entire contents of a file. The underlying file will _not_ be closed automatically. | ||
}): Promise<Buffer>; | ||
readFile(_options: (fs.ObjectEncodingOptions & FlagAndOpenMode) | BufferEncoding): Promise<string>; | ||
readFile(_options: (fs.ObjectEncodingOptions & promises.FlagAndOpenMode) | BufferEncoding): Promise<string>; | ||
/** | ||
@@ -159,3 +158,3 @@ * Returns a `ReadableStream` that may be used to read the files data. | ||
*/ | ||
createReadStream(options?: CreateReadStreamOptions): ReadStream; | ||
createReadStream(options?: promises.CreateReadStreamOptions): ReadStream; | ||
/** | ||
@@ -165,3 +164,3 @@ * Creates a stream for writing to the file. | ||
*/ | ||
createWriteStream(options?: CreateWriteStreamOptions): WriteStream; | ||
createWriteStream(options?: promises.CreateWriteStreamOptions): WriteStream; | ||
} | ||
@@ -308,5 +307,5 @@ export declare function rename(oldPath: fs.PathLike, newPath: fs.PathLike): Promise<void>; | ||
export declare function realpath(path: fs.PathLike, options?: fs.EncodingOption | BufferEncoding): Promise<string>; | ||
export declare function watch(filename: fs.PathLike, options?: fs.WatchOptions | BufferEncoding): AsyncIterable<FileChangeInfo<string>>; | ||
export declare function watch(filename: fs.PathLike, options: fs.WatchOptions | fs.BufferEncodingOption): AsyncIterable<FileChangeInfo<Buffer>>; | ||
export declare function watch(filename: fs.PathLike, options?: fs.WatchOptions | string): AsyncIterable<FileChangeInfo<string>> | AsyncIterable<FileChangeInfo<Buffer>>; | ||
export declare function watch(filename: fs.PathLike, options?: fs.WatchOptions | BufferEncoding): AsyncIterable<promises.FileChangeInfo<string>>; | ||
export declare function watch(filename: fs.PathLike, options: fs.WatchOptions | fs.BufferEncodingOption): AsyncIterable<promises.FileChangeInfo<Buffer>>; | ||
export declare function watch(filename: fs.PathLike, options?: fs.WatchOptions | string): AsyncIterable<promises.FileChangeInfo<string>> | AsyncIterable<promises.FileChangeInfo<Buffer>>; | ||
export declare function access(path: fs.PathLike, mode?: number): Promise<void>; | ||
@@ -313,0 +312,0 @@ /** |
@@ -874,16 +874,24 @@ var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) { | ||
[Symbol.asyncIterator]() { | ||
const watcher = new FSWatcher(filename.toString(), typeof options != 'string' ? options : { encoding: options }); | ||
function withDone(done) { | ||
return function () { | ||
const event = Promise.withResolvers(); | ||
watcher.on('change', (eventType, filename) => { | ||
event.resolve({ value: { eventType, filename }, done }); | ||
}); | ||
return event.promise; | ||
}; | ||
const watcher = new FSWatcher(filename.toString(), typeof options !== 'string' ? options : { encoding: options }); | ||
// A queue to hold change events, since we need to resolve them in the async iterator | ||
const eventQueue = []; | ||
watcher.on('change', (eventType, filename) => { | ||
eventQueue.shift()?.({ value: { eventType, filename }, done: false }); | ||
}); | ||
function cleanup() { | ||
watcher.close(); | ||
for (const resolve of eventQueue) { | ||
resolve({ value: null, done: true }); | ||
} | ||
eventQueue.length = 0; // Clear the queue | ||
return Promise.resolve({ value: null, done: true }); | ||
} | ||
return { | ||
next: withDone(false), | ||
return: withDone(true), | ||
throw: withDone(true), | ||
async next() { | ||
const { promise, resolve } = Promise.withResolvers(); | ||
eventQueue.push(resolve); | ||
return promise; | ||
}, | ||
return: cleanup, | ||
throw: cleanup, | ||
}; | ||
@@ -890,0 +898,0 @@ }, |
@@ -1,2 +0,2 @@ | ||
import type * as Node from 'fs'; | ||
import type * as Node from 'node:fs'; | ||
import { Readable, Writable } from 'readable-stream'; | ||
@@ -3,0 +3,0 @@ import type { Callback } from '../utils.js'; |
@@ -1,2 +0,2 @@ | ||
import type * as Node from 'fs'; | ||
import type * as Node from 'node:fs'; | ||
import { type Credentials } from './credentials.js'; | ||
@@ -3,0 +3,0 @@ import { S_IFDIR, S_IFLNK, S_IFREG } from './emulation/constants.js'; |
{ | ||
"name": "@zenfs/core", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"description": "A filesystem, anywhere", | ||
@@ -5,0 +5,0 @@ "funding": { |
@@ -1,2 +0,2 @@ | ||
import type { FileReadResult } from 'fs/promises'; | ||
import type { FileReadResult } from 'node:fs/promises'; | ||
import { InMemoryStore } from './backends/memory.js'; | ||
@@ -3,0 +3,0 @@ import { StoreFS } from './backends/store/fs.js'; |
@@ -1,2 +0,2 @@ | ||
import type { Dir as _Dir, Dirent as _Dirent } from 'fs'; | ||
import type { Dir as _Dir, Dirent as _Dirent } from 'node:fs'; | ||
import { Errno, ErrnoError } from '../error.js'; | ||
@@ -3,0 +3,0 @@ import type { Stats } from '../stats.js'; |
@@ -5,7 +5,5 @@ /* eslint-disable @typescript-eslint/no-redundant-type-constituents */ | ||
import type * as promises from 'node:fs/promises'; | ||
import type { CreateReadStreamOptions, CreateWriteStreamOptions, FileChangeInfo, FileReadResult, FlagAndOpenMode } from 'node:fs/promises'; | ||
import type { Stream } from 'node:stream'; | ||
import type { ReadableStream as TReadableStream } from 'node:stream/web'; | ||
import type { ReadableStreamController, ReadableStream as TReadableStream } from 'node:stream/web'; | ||
import type { Interface as ReadlineInterface } from 'readline'; | ||
import type { ReadableStreamController } from 'stream/web'; | ||
import { Errno, ErrnoError } from '../error.js'; | ||
@@ -111,3 +109,3 @@ import type { File } from '../file.js'; | ||
*/ | ||
public async appendFile(data: string | Uint8Array, _options: (fs.ObjectEncodingOptions & FlagAndOpenMode) | BufferEncoding = {}): Promise<void> { | ||
public async appendFile(data: string | Uint8Array, _options: (fs.ObjectEncodingOptions & promises.FlagAndOpenMode) | BufferEncoding = {}): Promise<void> { | ||
const options = normalizeOptions(_options, 'utf8', 'a', 0o644); | ||
@@ -134,3 +132,3 @@ const flag = parseFlag(options.flag); | ||
*/ | ||
public read<TBuffer extends NodeJS.ArrayBufferView>(buffer: TBuffer, offset?: number, length?: number, position?: number | null): Promise<FileReadResult<TBuffer>> { | ||
public read<TBuffer extends NodeJS.ArrayBufferView>(buffer: TBuffer, offset?: number, length?: number, position?: number | null): Promise<promises.FileReadResult<TBuffer>> { | ||
if (isNaN(+position!)) { | ||
@@ -149,4 +147,4 @@ position = this.file.position; | ||
public async readFile(_options?: { flag?: fs.OpenMode }): Promise<Buffer>; | ||
public async readFile(_options: (fs.ObjectEncodingOptions & FlagAndOpenMode) | BufferEncoding): Promise<string>; | ||
public async readFile(_options?: (fs.ObjectEncodingOptions & FlagAndOpenMode) | BufferEncoding): Promise<string | Buffer> { | ||
public async readFile(_options: (fs.ObjectEncodingOptions & promises.FlagAndOpenMode) | BufferEncoding): Promise<string>; | ||
public async readFile(_options?: (fs.ObjectEncodingOptions & promises.FlagAndOpenMode) | BufferEncoding): Promise<string | Buffer> { | ||
const options = normalizeOptions(_options, null, 'r', 0o444); | ||
@@ -341,3 +339,3 @@ const flag = parseFlag(options.flag); | ||
*/ | ||
public createReadStream(options?: CreateReadStreamOptions): ReadStream { | ||
public createReadStream(options?: promises.CreateReadStreamOptions): ReadStream { | ||
const stream = new ReadStream({ | ||
@@ -367,3 +365,3 @@ highWaterMark: options?.highWaterMark || 64 * 1024, | ||
*/ | ||
public createWriteStream(options?: CreateWriteStreamOptions): WriteStream { | ||
public createWriteStream(options?: promises.CreateWriteStreamOptions): WriteStream { | ||
const streamOptions = { | ||
@@ -896,24 +894,34 @@ highWaterMark: options?.highWaterMark, | ||
export function watch(filename: fs.PathLike, options?: fs.WatchOptions | BufferEncoding): AsyncIterable<FileChangeInfo<string>>; | ||
export function watch(filename: fs.PathLike, options: fs.WatchOptions | fs.BufferEncodingOption): AsyncIterable<FileChangeInfo<Buffer>>; | ||
export function watch(filename: fs.PathLike, options?: fs.WatchOptions | string): AsyncIterable<FileChangeInfo<string>> | AsyncIterable<FileChangeInfo<Buffer>>; | ||
export function watch<T extends string | Buffer>(filename: fs.PathLike, options: fs.WatchOptions | string = {}): AsyncIterable<FileChangeInfo<T>> { | ||
export function watch(filename: fs.PathLike, options?: fs.WatchOptions | BufferEncoding): AsyncIterable<promises.FileChangeInfo<string>>; | ||
export function watch(filename: fs.PathLike, options: fs.WatchOptions | fs.BufferEncodingOption): AsyncIterable<promises.FileChangeInfo<Buffer>>; | ||
export function watch(filename: fs.PathLike, options?: fs.WatchOptions | string): AsyncIterable<promises.FileChangeInfo<string>> | AsyncIterable<promises.FileChangeInfo<Buffer>>; | ||
export function watch<T extends string | Buffer>(filename: fs.PathLike, options: fs.WatchOptions | string = {}): AsyncIterable<promises.FileChangeInfo<T>> { | ||
return { | ||
[Symbol.asyncIterator](): AsyncIterator<FileChangeInfo<T>> { | ||
const watcher = new FSWatcher<T>(filename.toString(), typeof options != 'string' ? options : { encoding: options as BufferEncoding | 'buffer' }); | ||
[Symbol.asyncIterator](): AsyncIterator<promises.FileChangeInfo<T>> { | ||
const watcher = new FSWatcher<T>(filename.toString(), typeof options !== 'string' ? options : { encoding: options as BufferEncoding | 'buffer' }); | ||
function withDone(done: boolean) { | ||
return function () { | ||
const event = Promise.withResolvers<IteratorResult<FileChangeInfo<T>>>(); | ||
watcher.on('change', (eventType, filename) => { | ||
event.resolve({ value: { eventType, filename }, done }); | ||
}); | ||
return event.promise; | ||
}; | ||
// A queue to hold change events, since we need to resolve them in the async iterator | ||
const eventQueue: ((value: IteratorResult<promises.FileChangeInfo<T>>) => void)[] = []; | ||
watcher.on('change', (eventType: promises.FileChangeInfo<T>['eventType'], filename: T) => { | ||
eventQueue.shift()?.({ value: { eventType, filename }, done: false }); | ||
}); | ||
function cleanup() { | ||
watcher.close(); | ||
for (const resolve of eventQueue) { | ||
resolve({ value: null, done: true }); | ||
} | ||
eventQueue.length = 0; // Clear the queue | ||
return Promise.resolve({ value: null, done: true as const }); | ||
} | ||
return { | ||
next: withDone(false), | ||
return: withDone(true), | ||
throw: withDone(true), | ||
async next() { | ||
const { promise, resolve } = Promise.withResolvers<IteratorResult<promises.FileChangeInfo<T>>>(); | ||
eventQueue.push(resolve); | ||
return promise; | ||
}, | ||
return: cleanup, | ||
throw: cleanup, | ||
}; | ||
@@ -920,0 +928,0 @@ }, |
@@ -1,2 +0,2 @@ | ||
import type * as Node from 'fs'; | ||
import type * as Node from 'node:fs'; | ||
import { Readable, Writable } from 'readable-stream'; | ||
@@ -3,0 +3,0 @@ import type { Callback } from '../utils.js'; |
@@ -1,2 +0,2 @@ | ||
import type * as Node from 'fs'; | ||
import type * as Node from 'node:fs'; | ||
import { credentials, type Credentials } from './credentials.js'; | ||
@@ -3,0 +3,0 @@ import { S_IFBLK, S_IFCHR, S_IFDIR, S_IFIFO, S_IFLNK, S_IFMT, S_IFREG, S_IFSOCK, S_IRWXG, S_IRWXO, S_IRWXU, size_max } from './emulation/constants.js'; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
757830
20825