New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@zenfs/core

Package Overview
Dependencies
Maintainers
1
Versions
170
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@zenfs/core - npm Package Compare versions

Comparing version 0.12.10 to 0.13.0

14

dist/backends/index/fs.d.ts

@@ -7,3 +7,3 @@ import type { Cred } from '../../cred.js';

import { Index } from './index.js';
declare const IndexFS_base: (abstract new (...args: any[]) => {
declare const IndexFS_base: import("../../filesystem.js").Mixin<typeof FileSystem, {
metadata(): import("../../filesystem.js").FileSystemMetadata;

@@ -24,13 +24,3 @@ rename(oldPath: string, newPath: string, cred: Cred): Promise<void>;

syncSync(path: string, data: Uint8Array, stats: Readonly<Stats>): void;
_disableSync?: boolean | undefined;
ready(): Promise<void>;
stat(path: string, cred: Cred): Promise<Stats>;
statSync(path: string, cred: Cred): Stats;
openFile(path: string, flag: string, cred: Cred): Promise<import("../../file.js").File>;
openFileSync(path: string, flag: string, cred: Cred): import("../../file.js").File;
readdir(path: string, cred: Cred): Promise<string[]>;
readdirSync(path: string, cred: Cred): string[];
exists(path: string, cred: Cred): Promise<boolean>;
existsSync(path: string, cred: Cred): boolean;
}) & typeof FileSystem;
}>;
export declare abstract class IndexFS extends IndexFS_base {

@@ -37,0 +27,0 @@ private indexData;

@@ -43,6 +43,5 @@ /// <reference types="node" resolution-mode="require"/>

type FSMethod = keyof FSMethods;
declare const PortFS_base: (abstract new (...args: any[]) => {
declare const PortFS_base: import("../../filesystem.js").Mixin<typeof FileSystem, {
_sync?: FileSystem | undefined;
queueDone(): Promise<void>;
metadata(): FileSystemMetadata;
ready(): Promise<void>;

@@ -59,16 +58,3 @@ renameSync(oldPath: string, newPath: string, cred: Cred): void;

syncSync(path: string, data: Uint8Array, stats: Readonly<Stats>): void;
_disableSync?: boolean | undefined;
rename(oldPath: string, newPath: string, cred: Cred): Promise<void>;
stat(path: string, cred: Cred): Promise<Stats>;
openFile(path: string, flag: string, cred: Cred): Promise<File>;
createFile(path: string, flag: string, mode: number, cred: Cred): Promise<File>;
unlink(path: string, cred: Cred): Promise<void>;
rmdir(path: string, cred: Cred): Promise<void>;
mkdir(path: string, mode: number, cred: Cred): Promise<void>;
readdir(path: string, cred: Cred): Promise<string[]>;
exists(path: string, cred: Cred): Promise<boolean>;
existsSync(path: string, cred: Cred): boolean;
link(srcpath: string, dstpath: string, cred: Cred): Promise<void>;
sync(path: string, data: Uint8Array, stats: Readonly<Stats>): Promise<void>;
}) & typeof FileSystem;
}>;
/**

@@ -75,0 +61,0 @@ * PortFS lets you access a ZenFS instance that is running in a port, or the other way around.

18

dist/emulation/promises.js

@@ -511,10 +511,24 @@ import { Buffer } from 'buffer';

export async function mkdir(path, options) {
options = typeof options === 'object' ? options : { mode: options };
const mode = normalizeMode(options?.mode, 0o777);
path = normalizePath(path);
path = (await exists(path)) ? await realpath(path) : path;
const { fs, path: resolved } = resolveMount(path);
const errorPaths = { [resolved]: path };
try {
await fs.mkdir(resolved, normalizeMode(typeof options == 'object' ? options?.mode : options, 0o777), cred);
if (!options?.recursive) {
await fs.mkdir(resolved, mode, cred);
}
const dirs = [];
for (let dir = resolved, origDir = path; !(await fs.exists(dir, cred)); dir = dirname(dir), origDir = dirname(origDir)) {
dirs.unshift(dir);
errorPaths[dir] = origDir;
}
for (const dir of dirs) {
await fs.mkdir(dir, mode, cred);
}
return dirs[0];
}
catch (e) {
throw fixError(e, { [resolved]: path });
throw fixError(e, errorPaths);
}

@@ -521,0 +535,0 @@ }

@@ -369,11 +369,24 @@ import { Buffer } from 'buffer';

export function mkdirSync(path, options) {
const mode = normalizeMode(typeof options == 'number' || typeof options == 'string' ? options : options?.mode, 0o777);
const recursive = typeof options == 'object' && options?.recursive;
options = typeof options === 'object' ? options : { mode: options };
const mode = normalizeMode(options?.mode, 0o777);
path = normalizePath(path);
const { fs, path: resolved } = resolveMount(existsSync(path) ? realpathSync(path) : path);
path = existsSync(path) ? realpathSync(path) : path;
const { fs, path: resolved } = resolveMount(path);
const errorPaths = { [resolved]: path };
try {
return fs.mkdirSync(resolved, mode, cred);
if (!options?.recursive) {
return fs.mkdirSync(resolved, mode, cred);
}
const dirs = [];
for (let dir = resolved, original = path; !fs.existsSync(dir, cred); dir = dirname(dir), original = dirname(original)) {
dirs.unshift(dir);
errorPaths[dir] = original;
}
for (const dir of dirs) {
fs.mkdirSync(dir, mode, cred);
}
return dirs[0];
}
catch (e) {
throw fixError(e, { [resolved]: path });
throw fixError(e, errorPaths);
}

@@ -380,0 +393,0 @@ }

@@ -0,1 +1,2 @@

import type { ExtractProperties } from 'utilium';
import { type Cred } from './cred.js';

@@ -73,3 +74,3 @@ import { type File } from './file.js';

_disableSync?: boolean;
constructor();
constructor(...args: any[]);
ready(): Promise<void>;

@@ -173,34 +174,31 @@ /**

/**
* `TBase` with `TMixin` mixed-in.
* @internal @experimental
*/
export type Mixin<TBase extends typeof FileSystem, TMixin> = (abstract new (...args: any[]) => TMixin) & TBase;
/**
* Asynchronous `FileSystem` methods. This is a convience type.
* @internal
*/
declare abstract class SyncFS extends FileSystem {
metadata(): FileSystemMetadata;
ready(): Promise<void>;
exists(path: string, cred: Cred): Promise<boolean>;
rename(oldPath: string, newPath: string, cred: Cred): Promise<void>;
stat(path: string, cred: Cred): Promise<Stats>;
createFile(path: string, flag: string, mode: number, cred: Cred): Promise<File>;
openFile(path: string, flag: string, cred: Cred): Promise<File>;
unlink(path: string, cred: Cred): Promise<void>;
rmdir(path: string, cred: Cred): Promise<void>;
mkdir(path: string, mode: number, cred: Cred): Promise<void>;
readdir(path: string, cred: Cred): Promise<string[]>;
link(srcpath: string, dstpath: string, cred: Cred): Promise<void>;
sync(path: string, data: Uint8Array, stats: Readonly<Stats>): Promise<void>;
}
export type _AsyncFSMethods = ExtractProperties<FileSystem, (...args: any[]) => Promise<unknown>>;
/**
* Implements the asynchronous API in terms of the synchronous API.
*/
export declare function Sync<T extends abstract new (...args: any[]) => FileSystem>(FS: T): (abstract new (...args: any[]) => SyncFS) & T;
export declare function Sync<T extends typeof FileSystem>(FS: T): Mixin<T, _AsyncFSMethods>;
/**
* @internal
* Async() implements synchronous methods on an asynchronous file system
*
* Implementing classes must define `_sync` for the synchronous file system used as a cache.
* Synchronous methods on an asynchronous FS are implemented by:
* - Performing operations over the in-memory copy,
* while asynchronously pipelining them to the backing store.
* - During loading, the contents of the async file system are preloaded into the synchronous store.
*
*/
declare abstract class AsyncFS extends FileSystem {
export declare function Async<T extends typeof FileSystem>(FS: T): Mixin<T, {
/**
* protected can't be used because of TS quirks.
* @hidden @protected
* @internal @protected
*/
abstract _sync?: FileSystem;
_sync?: FileSystem;
queueDone(): Promise<void>;
metadata(): FileSystemMetadata;
ready(): Promise<void>;

@@ -217,18 +215,7 @@ renameSync(oldPath: string, newPath: string, cred: Cred): void;

syncSync(path: string, data: Uint8Array, stats: Readonly<Stats>): void;
}
}>;
/**
* Async() implements synchronous methods on an asynchronous file system
*
* Implementing classes must define `_sync` for the synchronous file system used as a cache.
* Synchronous methods on an asynchronous FS are implemented by:
* - Performing operations over the in-memory copy,
* while asynchronously pipelining them to the backing store.
* - During loading, the contents of the async file system are eloaded into the synchronous store.
*
* Implements the non-readonly methods to throw `EROFS`
*/
export declare function Async<T extends abstract new (...args: any[]) => FileSystem>(FS: T): (abstract new (...args: any[]) => AsyncFS) & T;
/**
* @internal
*/
declare abstract class ReadonlyFS extends FileSystem {
export declare function Readonly<T extends typeof FileSystem>(FS: T): Mixin<T, {
metadata(): FileSystemMetadata;

@@ -249,7 +236,2 @@ rename(oldPath: string, newPath: string, cred: Cred): Promise<void>;

syncSync(path: string, data: Uint8Array, stats: Readonly<Stats>): void;
}
/**
* Implements the non-readonly methods to throw `EROFS`
*/
export declare function Readonly<T extends abstract new (...args: any[]) => FileSystem>(FS: T): (abstract new (...args: any[]) => ReadonlyFS) & T;
export {};
}>;

@@ -1,4 +0,4 @@

import { ErrnoError, Errno } from './error.js';
import { rootCred } from './cred.js';
import { join } from './emulation/path.js';
import { Errno, ErrnoError } from './error.js';
import { PreloadFile, parseFlag } from './file.js';

@@ -28,3 +28,4 @@ import { ZenFsType } from './stats.js';

}
constructor() { }
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars
constructor(...args) { }
async ready() { }

@@ -59,5 +60,4 @@ /**

*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function Sync(FS) {
class _SyncFS extends FS {
class SyncFS extends FS {
async exists(path, cred) {

@@ -97,3 +97,3 @@ return this.existsSync(path, cred);

}
return _SyncFS;
return SyncFS;
}

@@ -107,8 +107,7 @@ /**

* while asynchronously pipelining them to the backing store.
* - During loading, the contents of the async file system are eloaded into the synchronous store.
* - During loading, the contents of the async file system are preloaded into the synchronous store.
*
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function Async(FS) {
class _AsyncFS extends FS {
class AsyncFS extends FS {
constructor() {

@@ -261,3 +260,3 @@ super(...arguments);

}
return _AsyncFS;
return AsyncFS;
}

@@ -267,5 +266,4 @@ /**

*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function Readonly(FS) {
class _ReadonlyFS extends FS {
class ReadonlyFS extends FS {
metadata() {

@@ -318,3 +316,3 @@ return { ...super.metadata(), readonly: true };

}
return _ReadonlyFS;
return ReadonlyFS;
}
{
"name": "@zenfs/core",
"version": "0.12.10",
"description": "A filesystem in your browser",
"version": "0.13.0",
"description": "A filesystem, anywhere",
"main": "dist/index.js",

@@ -50,3 +50,3 @@ "types": "dist/index.d.ts",

"build": "node scripts/build.js --globalName=ZenFS --entry src/index.ts",
"build:docs": "typedoc --out docs --name ZenFS src/index.ts",
"build:docs": "typedoc",
"dev": "npm run build -- --watch",

@@ -77,4 +77,5 @@ "prepublishOnly": "npm run build"

"typedoc": "^0.25.13",
"typedoc-plugin-remove-references": "^0.0.6",
"typescript": "^5.4.0"
}
}

@@ -659,9 +659,26 @@ import { Buffer } from 'buffer';

export async function mkdir(path: fs.PathLike, options?: fs.Mode | fs.MakeDirectoryOptions | null): Promise<string | undefined | void> {
options = typeof options === 'object' ? options : { mode: options };
const mode = normalizeMode(options?.mode, 0o777);
path = normalizePath(path);
path = (await exists(path)) ? await realpath(path) : path;
const { fs, path: resolved } = resolveMount(path);
const errorPaths: Record<string, string> = { [resolved]: path };
try {
await fs.mkdir(resolved, normalizeMode(typeof options == 'object' ? options?.mode : options, 0o777), cred);
if (!options?.recursive) {
await fs.mkdir(resolved, mode, cred);
}
const dirs: string[] = [];
for (let dir = resolved, origDir = path; !(await fs.exists(dir, cred)); dir = dirname(dir), origDir = dirname(origDir)) {
dirs.unshift(dir);
errorPaths[dir] = origDir;
}
for (const dir of dirs) {
await fs.mkdir(dir, mode, cred);
}
return dirs[0];
} catch (e) {
throw fixError(e as Error, { [resolved]: path });
throw fixError(e as Error, errorPaths);
}

@@ -668,0 +685,0 @@ }

@@ -484,10 +484,26 @@ import { Buffer } from 'buffer';

export function mkdirSync(path: fs.PathLike, options?: fs.Mode | fs.MakeDirectoryOptions | null): string | undefined | void {
const mode: fs.Mode = normalizeMode(typeof options == 'number' || typeof options == 'string' ? options : options?.mode, 0o777);
const recursive = typeof options == 'object' && options?.recursive;
options = typeof options === 'object' ? options : { mode: options };
const mode = normalizeMode(options?.mode, 0o777);
path = normalizePath(path);
const { fs, path: resolved } = resolveMount(existsSync(path) ? realpathSync(path) : path);
path = existsSync(path) ? realpathSync(path) : path;
const { fs, path: resolved } = resolveMount(path);
const errorPaths: Record<string, string> = { [resolved]: path };
try {
return fs.mkdirSync(resolved, mode, cred);
if (!options?.recursive) {
return fs.mkdirSync(resolved, mode, cred);
}
const dirs: string[] = [];
for (let dir = resolved, original = path; !fs.existsSync(dir, cred); dir = dirname(dir), original = dirname(original)) {
dirs.unshift(dir);
errorPaths[dir] = original;
}
for (const dir of dirs) {
fs.mkdirSync(dir, mode, cred);
}
return dirs[0];
} catch (e) {
throw fixError(e as Error, { [resolved]: path });
throw fixError(e as Error, errorPaths);
}

@@ -494,0 +510,0 @@ }

import type { ExtractProperties } from 'utilium';
import { ErrnoError, Errno } from './error.js';
import { rootCred, type Cred } from './cred.js';
import { join } from './emulation/path.js';
import { Errno, ErrnoError } from './error.js';
import { PreloadFile, parseFlag, type File } from './file.js';

@@ -100,3 +100,4 @@ import { ZenFsType, type Stats } from './stats.js';

public constructor() {}
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars
public constructor(...args: any[]) {}

@@ -231,19 +232,14 @@ public async ready(): Promise<void> {}

/**
* `TBase` with `TMixin` mixed-in.
* @internal @experimental
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type Mixin<TBase extends typeof FileSystem, TMixin> = (abstract new (...args: any[]) => TMixin) & TBase;
/**
* Asynchronous `FileSystem` methods. This is a convience type.
* @internal
*/
declare abstract class SyncFS extends FileSystem {
public metadata(): FileSystemMetadata;
public ready(): Promise<void>;
public exists(path: string, cred: Cred): Promise<boolean>;
public rename(oldPath: string, newPath: string, cred: Cred): Promise<void>;
public stat(path: string, cred: Cred): Promise<Stats>;
public createFile(path: string, flag: string, mode: number, cred: Cred): Promise<File>;
public openFile(path: string, flag: string, cred: Cred): Promise<File>;
public unlink(path: string, cred: Cred): Promise<void>;
public rmdir(path: string, cred: Cred): Promise<void>;
public mkdir(path: string, mode: number, cred: Cred): Promise<void>;
public readdir(path: string, cred: Cred): Promise<string[]>;
public link(srcpath: string, dstpath: string, cred: Cred): Promise<void>;
public sync(path: string, data: Uint8Array, stats: Readonly<Stats>): Promise<void>;
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type _AsyncFSMethods = ExtractProperties<FileSystem, (...args: any[]) => Promise<unknown>>;

@@ -253,5 +249,4 @@ /**

*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function Sync<T extends abstract new (...args: any[]) => FileSystem>(FS: T): (abstract new (...args: any[]) => SyncFS) & T {
abstract class _SyncFS extends FS implements SyncFS {
export function Sync<T extends typeof FileSystem>(FS: T): Mixin<T, _AsyncFSMethods> {
abstract class SyncFS extends FS implements _AsyncFSMethods {
public async exists(path: string, cred: Cred): Promise<boolean> {

@@ -301,3 +296,3 @@ return this.existsSync(path, cred);

}
return _SyncFS;
return SyncFS;
}

@@ -308,32 +303,5 @@

*/
declare abstract class AsyncFS extends FileSystem {
/**
* protected can't be used because of TS quirks.
* @hidden @protected
*/
abstract _sync?: FileSystem;
public queueDone(): Promise<void>;
public metadata(): FileSystemMetadata;
public ready(): Promise<void>;
public renameSync(oldPath: string, newPath: string, cred: Cred): void;
public statSync(path: string, cred: Cred): Stats;
public createFileSync(path: string, flag: string, mode: number, cred: Cred): File;
public openFileSync(path: string, flag: string, cred: Cred): File;
public unlinkSync(path: string, cred: Cred): void;
public rmdirSync(path: string, cred: Cred): void;
public mkdirSync(path: string, mode: number, cred: Cred): void;
public readdirSync(path: string, cred: Cred): string[];
public linkSync(srcpath: string, dstpath: string, cred: Cred): void;
public syncSync(path: string, data: Uint8Array, stats: Readonly<Stats>): void;
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
type AsyncMethods = ExtractProperties<FileSystem, (...args: any[]) => Promise<unknown>>;
/**
* @internal
*/
type AsyncOperation = {
[K in keyof AsyncMethods]: [K, ...Parameters<FileSystem[K]>];
}[keyof AsyncMethods];
[K in keyof _AsyncFSMethods]: [K, ...Parameters<FileSystem[K]>];
}[keyof _AsyncFSMethods];

@@ -347,9 +315,30 @@ /**

* while asynchronously pipelining them to the backing store.
* - During loading, the contents of the async file system are eloaded into the synchronous store.
* - During loading, the contents of the async file system are preloaded into the synchronous store.
*
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function Async<T extends abstract new (...args: any[]) => FileSystem>(FS: T): (abstract new (...args: any[]) => AsyncFS) & T {
abstract class _AsyncFS extends FS implements AsyncFS {
export function Async<T extends typeof FileSystem>(
FS: T
): Mixin<
T,
{
/**
* @internal @protected
*/
_sync?: FileSystem;
queueDone(): Promise<void>;
ready(): Promise<void>;
renameSync(oldPath: string, newPath: string, cred: Cred): void;
statSync(path: string, cred: Cred): Stats;
createFileSync(path: string, flag: string, mode: number, cred: Cred): File;
openFileSync(path: string, flag: string, cred: Cred): File;
unlinkSync(path: string, cred: Cred): void;
rmdirSync(path: string, cred: Cred): void;
mkdirSync(path: string, mode: number, cred: Cred): void;
readdirSync(path: string, cred: Cred): string[];
linkSync(srcpath: string, dstpath: string, cred: Cred): void;
syncSync(path: string, data: Uint8Array, stats: Readonly<Stats>): void;
}
> {
abstract class AsyncFS extends FS {
/**
* Queue of pending asynchronous operations.

@@ -519,32 +508,31 @@ */

return _AsyncFS;
return AsyncFS;
}
/**
* @internal
*/
declare abstract class ReadonlyFS extends FileSystem {
public metadata(): FileSystemMetadata;
public rename(oldPath: string, newPath: string, cred: Cred): Promise<void>;
public renameSync(oldPath: string, newPath: string, cred: Cred): void;
public createFile(path: string, flag: string, mode: number, cred: Cred): Promise<File>;
public createFileSync(path: string, flag: string, mode: number, cred: Cred): File;
public unlink(path: string, cred: Cred): Promise<void>;
public unlinkSync(path: string, cred: Cred): void;
public rmdir(path: string, cred: Cred): Promise<void>;
public rmdirSync(path: string, cred: Cred): void;
public mkdir(path: string, mode: number, cred: Cred): Promise<void>;
public mkdirSync(path: string, mode: number, cred: Cred): void;
public link(srcpath: string, dstpath: string, cred: Cred): Promise<void>;
public linkSync(srcpath: string, dstpath: string, cred: Cred): void;
public sync(path: string, data: Uint8Array, stats: Readonly<Stats>): Promise<void>;
public syncSync(path: string, data: Uint8Array, stats: Readonly<Stats>): void;
}
/**
* Implements the non-readonly methods to throw `EROFS`
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function Readonly<T extends abstract new (...args: any[]) => FileSystem>(FS: T): (abstract new (...args: any[]) => ReadonlyFS) & T {
abstract class _ReadonlyFS extends FS implements ReadonlyFS {
export function Readonly<T extends typeof FileSystem>(
FS: T
): Mixin<
T,
{
metadata(): FileSystemMetadata;
rename(oldPath: string, newPath: string, cred: Cred): Promise<void>;
renameSync(oldPath: string, newPath: string, cred: Cred): void;
createFile(path: string, flag: string, mode: number, cred: Cred): Promise<File>;
createFileSync(path: string, flag: string, mode: number, cred: Cred): File;
unlink(path: string, cred: Cred): Promise<void>;
unlinkSync(path: string, cred: Cred): void;
rmdir(path: string, cred: Cred): Promise<void>;
rmdirSync(path: string, cred: Cred): void;
mkdir(path: string, mode: number, cred: Cred): Promise<void>;
mkdirSync(path: string, mode: number, cred: Cred): void;
link(srcpath: string, dstpath: string, cred: Cred): Promise<void>;
linkSync(srcpath: string, dstpath: string, cred: Cred): void;
sync(path: string, data: Uint8Array, stats: Readonly<Stats>): Promise<void>;
syncSync(path: string, data: Uint8Array, stats: Readonly<Stats>): void;
}
> {
abstract class ReadonlyFS extends FS {
public metadata(): FileSystemMetadata {

@@ -611,3 +599,3 @@ return { ...super.metadata(), readonly: true };

}
return _ReadonlyFS;
return ReadonlyFS;
}

@@ -12,3 +12,9 @@ {

"include": ["src/**/*.ts"],
"exclude": ["node_modules"]
"exclude": ["node_modules"],
"typedocOptions": {
"entryPoints": ["./src/index.ts"],
"out": "docs",
"name": "ZenFS",
"plugin": ["typedoc-plugin-remove-references"]
}
}

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

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc