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

@zenfs/core

Package Overview
Dependencies
Maintainers
1
Versions
156
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.0.11 to 0.0.12

10

dist/backends/AsyncMirror.js

@@ -104,6 +104,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

const stats = fd.getStats();
this._sync.writeFileSync(fd.getPath(), fd.getBuffer(), null, FileFlag.getFileFlag('w'), stats.mode, stats.getCred(0, 0));
this._sync.writeFileSync(fd.getPath(), fd.getBuffer(), FileFlag.getFileFlag('w'), stats.mode, stats.getCred(0, 0));
this.enqueueOp({
apiMethod: 'writeFile',
arguments: [fd.getPath(), fd.getBuffer(), null, fd.getFlag(), stats.mode, stats.getCred(0, 0)],
arguments: [fd.getPath(), fd.getBuffer(), fd.getFlag(), stats.mode, stats.getCred(0, 0)],
});

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

fd.closeSync();
return new MirrorFile(this, p, flag, this._sync.statSync(p, cred), this._sync.readFileSync(p, null, FileFlag.getFileFlag('r'), cred));
return new MirrorFile(this, p, flag, this._sync.statSync(p, cred), this._sync.readFileSync(p, FileFlag.getFileFlag('r'), cred));
}

@@ -193,4 +193,4 @@ unlinkSync(p, cred) {

}), copyFile = (p, mode) => __awaiter(this, void 0, void 0, function* () {
const data = yield this._async.readFile(p, null, FileFlag.getFileFlag('r'), Cred.Root);
this._sync.writeFileSync(p, data, null, FileFlag.getFileFlag('w'), mode, Cred.Root);
const data = yield this._async.readFile(p, FileFlag.getFileFlag('r'), Cred.Root);
this._sync.writeFileSync(p, data, FileFlag.getFileFlag('w'), mode, Cred.Root);
}), copyItem = (p) => __awaiter(this, void 0, void 0, function* () {

@@ -197,0 +197,0 @@ const stats = yield this._async.stat(p, Cred.Root);

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

/// <reference types="node" resolution-mode="require"/>
import { FileContents, FileSystem, FileSystemMetadata } from '../filesystem.js';
import { FileSystem, FileSystemMetadata } from '../filesystem.js';
import { FileFlag } from '../file.js';

@@ -46,8 +45,8 @@ import { Stats } from '../stats.js';

truncateSync(p: string, len: number, cred: Cred): void;
readFile(fname: string, encoding: BufferEncoding, flag: FileFlag, cred: Cred): Promise<FileContents>;
readFileSync(fname: string, encoding: BufferEncoding, flag: FileFlag, cred: Cred): FileContents;
writeFile(fname: string, data: FileContents, encoding: BufferEncoding, flag: FileFlag, mode: number, cred: Cred): Promise<void>;
writeFileSync(fname: string, data: FileContents, encoding: BufferEncoding, flag: FileFlag, mode: number, cred: Cred): void;
appendFile(fname: string, data: FileContents, encoding: BufferEncoding, flag: FileFlag, mode: number, cred: Cred): Promise<void>;
appendFileSync(fname: string, data: FileContents, encoding: BufferEncoding, flag: FileFlag, mode: number, cred: Cred): void;
readFile(fname: string, flag: FileFlag, cred: Cred): Promise<Uint8Array>;
readFileSync(fname: string, flag: FileFlag, cred: Cred): Uint8Array;
writeFile(fname: string, data: Uint8Array, flag: FileFlag, mode: number, cred: Cred): Promise<void>;
writeFileSync(fname: string, data: Uint8Array, flag: FileFlag, mode: number, cred: Cred): void;
appendFile(fname: string, data: Uint8Array, flag: FileFlag, mode: number, cred: Cred): Promise<void>;
appendFileSync(fname: string, data: Uint8Array, flag: FileFlag, mode: number, cred: Cred): void;
chmod(p: string, mode: number, cred: Cred): Promise<void>;

@@ -54,0 +53,0 @@ chmodSync(p: string, mode: number, cred: Cred): void;

@@ -183,6 +183,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

}
readFile(fname, encoding, flag, cred) {
readFile(fname, flag, cred) {
return __awaiter(this, void 0, void 0, function* () {
yield this._mu.lock(fname);
const data = yield this._fs.readFile(fname, encoding, flag, cred);
const data = yield this._fs.readFile(fname, flag, cred);
this._mu.unlock(fname);

@@ -192,33 +192,33 @@ return data;

}
readFileSync(fname, encoding, flag, cred) {
readFileSync(fname, flag, cred) {
if (this._mu.isLocked(fname)) {
throw new Error('invalid sync call');
}
return this._fs.readFileSync(fname, encoding, flag, cred);
return this._fs.readFileSync(fname, flag, cred);
}
writeFile(fname, data, encoding, flag, mode, cred) {
writeFile(fname, data, flag, mode, cred) {
return __awaiter(this, void 0, void 0, function* () {
yield this._mu.lock(fname);
yield this._fs.writeFile(fname, data, encoding, flag, mode, cred);
yield this._fs.writeFile(fname, data, flag, mode, cred);
this._mu.unlock(fname);
});
}
writeFileSync(fname, data, encoding, flag, mode, cred) {
writeFileSync(fname, data, flag, mode, cred) {
if (this._mu.isLocked(fname)) {
throw new Error('invalid sync call');
}
return this._fs.writeFileSync(fname, data, encoding, flag, mode, cred);
return this._fs.writeFileSync(fname, data, flag, mode, cred);
}
appendFile(fname, data, encoding, flag, mode, cred) {
appendFile(fname, data, flag, mode, cred) {
return __awaiter(this, void 0, void 0, function* () {
yield this._mu.lock(fname);
yield this._fs.appendFile(fname, data, encoding, flag, mode, cred);
yield this._fs.appendFile(fname, data, flag, mode, cred);
this._mu.unlock(fname);
});
}
appendFileSync(fname, data, encoding, flag, mode, cred) {
appendFileSync(fname, data, flag, mode, cred) {
if (this._mu.isLocked(fname)) {
throw new Error('invalid sync call');
}
return this._fs.appendFileSync(fname, data, encoding, flag, mode, cred);
return this._fs.appendFileSync(fname, data, flag, mode, cred);
}

@@ -225,0 +225,0 @@ chmod(p, mode, cred) {

@@ -19,2 +19,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

import { CreateBackend } from './backend.js';
import { decode, encode } from '../utils.js';
/**

@@ -109,3 +110,3 @@ * @internal

yield this.createParentDirectoriesAsync(file.getPath(), stats.getCred(0, 0));
return this._writable.writeFile(file.getPath(), file.getBuffer(), null, getFlag('w'), stats.mode, stats.getCred(0, 0));
return this._writable.writeFile(file.getPath(), file.getBuffer(), getFlag('w'), stats.mode, stats.getCred(0, 0));
});

@@ -116,3 +117,3 @@ }

this.createParentDirectories(file.getPath(), stats.getCred(0, 0));
this._writable.writeFileSync(file.getPath(), file.getBuffer(), null, getFlag('w'), stats.mode, stats.getCred(0, 0));
this._writable.writeFileSync(file.getPath(), file.getBuffer(), getFlag('w'), stats.mode, stats.getCred(0, 0));
}

@@ -132,4 +133,4 @@ /**

try {
const data = (yield this._writable.readFile(deletionLogPath, 'utf8', getFlag('r'), Cred.Root));
this._deleteLog = data;
const data = yield this._writable.readFile(deletionLogPath, getFlag('r'), Cred.Root);
this._deleteLog = decode(data);
}

@@ -202,3 +203,3 @@ catch (err) {

}
yield this.writeFile(newPath, yield this.readFile(oldPath, null, getFlag('r'), cred), null, getFlag('w'), oldStats.mode, cred);
yield this.writeFile(newPath, yield this.readFile(oldPath, getFlag('r'), cred), getFlag('w'), oldStats.mode, cred);
}

@@ -258,3 +259,3 @@ if (oldPath !== newPath && (yield this.exists(oldPath, cred))) {

}
this.writeFileSync(newPath, this.readFileSync(oldPath, null, getFlag('r'), cred), null, getFlag('w'), oldStats.mode, cred);
this.writeFileSync(newPath, this.readFileSync(oldPath, getFlag('r'), cred), getFlag('w'), oldStats.mode, cred);
}

@@ -317,3 +318,3 @@ if (oldPath !== newPath && this.existsSync(oldPath, cred)) {

// Create an OverlayFile.
const buf = yield this._readable.readFile(p, null, getFlag('r'), cred);
const buf = yield this._readable.readFile(p, getFlag('r'), cred);
const stats = Stats.clone(yield this._readable.stat(p, cred));

@@ -355,3 +356,3 @@ stats.mode = mode;

// Create an OverlayFile.
const buf = this._readable.readFileSync(p, null, getFlag('r'), cred);
const buf = this._readable.readFileSync(p, getFlag('r'), cred);
const stats = Stats.clone(this._readable.statSync(p, cred));

@@ -591,3 +592,3 @@ stats.mode = mode;

this._writable
.writeFile(deletionLogPath, this._deleteLog, 'utf8', FileFlag.getFileFlag('w'), 0o644, cred)
.writeFile(deletionLogPath, encode(this._deleteLog), FileFlag.getFileFlag('w'), 0o644, cred)
.then(() => {

@@ -693,3 +694,3 @@ if (this._deleteLogUpdateNeeded) {

else {
this.writeFileSync(p, this._readable.readFileSync(p, null, getFlag('r'), cred), null, getFlag('w'), pStats.mode, cred);
this.writeFileSync(p, this._readable.readFileSync(p, getFlag('r'), cred), getFlag('w'), pStats.mode, cred);
}

@@ -704,3 +705,3 @@ }

else {
yield this.writeFile(p, yield this._readable.readFile(p, null, getFlag('r'), cred), null, getFlag('w'), pStats.mode, cred);
yield this.writeFile(p, yield this._readable.readFile(p, getFlag('r'), cred), getFlag('w'), pStats.mode, cred);
}

@@ -707,0 +708,0 @@ });

@@ -15,3 +15,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

import { normalizePath, normalizeMode, getFdForFile, normalizeOptions, fd2file, fdMap, normalizeTime, cred, nop, resolveFS, fixError, mounts } from './shared.js';
import { encode } from '../utils.js';
import { decode, encode } from '../utils.js';
/**

@@ -152,3 +152,10 @@ * Utility for FS ops. It handles

}
return doOp('readFile', true, filename, options.encoding, flag, cred);
const data = yield doOp('readFile', true, filename, flag, cred);
switch (options.encoding) {
case 'utf8':
case 'utf-8':
return decode(data);
default:
return data;
}
});

@@ -163,3 +170,7 @@ }

}
return doOp('writeFile', true, filename, data, options.encoding, flag, options.mode, cred);
if (typeof data != 'string' && !options.encoding) {
throw new ApiError(ErrorCode.EINVAL, 'Encoding not specified');
}
const encodedData = typeof data == 'string' ? encode(data) : data;
return doOp('writeFile', true, filename, encodedData, flag, options.mode, cred);
});

@@ -174,3 +185,7 @@ }

}
return doOp('appendFile', true, filename, data, options.encoding, flag, options.mode, cred);
if (typeof data != 'string' && !options.encoding) {
throw new ApiError(ErrorCode.EINVAL, 'Encoding not specified');
}
const encodedData = typeof data == 'string' ? encode(data) : data;
return doOp('appendFile', true, filename, encodedData, flag, options.mode, cred);
});

@@ -177,0 +192,0 @@ }

import { ApiError, ErrorCode } from '../ApiError.js';
import { FileFlag } from '../file.js';
import { normalizePath, cred, getFdForFile, normalizeMode, normalizeOptions, fdMap, fd2file, normalizeTime, resolveFS, fixError, mounts } from './shared.js';
import { encode } from '../utils.js';
import { decode, encode } from '../utils.js';
function doOp(...[name, resolveSymlinks, path, ...args]) {

@@ -110,3 +110,10 @@ path = normalizePath(path);

}
return doOp('readFileSync', true, filename, options.encoding, flag, cred);
const data = doOp('readFileSync', true, filename, flag, cred);
switch (options.encoding) {
case 'utf8':
case 'utf-8':
return decode(data);
default:
return data;
}
}

@@ -119,3 +126,7 @@ export function writeFileSync(filename, data, arg3) {

}
return doOp('writeFileSync', true, filename, data, options.encoding, flag, options.mode, cred);
if (typeof data != 'string' && !options.encoding) {
throw new ApiError(ErrorCode.EINVAL, 'Encoding not specified');
}
const encodedData = typeof data == 'string' ? encode(data) : data;
return doOp('writeFileSync', true, filename, encodedData, flag, options.mode, cred);
}

@@ -128,3 +139,7 @@ export function appendFileSync(filename, data, arg3) {

}
return doOp('appendFileSync', true, filename, data, options.encoding, flag, options.mode, cred);
if (typeof data != 'string' && !options.encoding) {
throw new ApiError(ErrorCode.EINVAL, 'Encoding not specified');
}
const encodedData = typeof data == 'string' ? encode(data) : data;
return doOp('appendFileSync', true, filename, encodedData, flag, options.mode, cred);
}

@@ -131,0 +146,0 @@ /**

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

/// <reference types="node" resolution-mode="require"/>
import { ApiError } from './ApiError.js';

@@ -182,15 +181,8 @@ import { Stats } from './stats.js';

* Asynchronously reads the entire contents of a file.
* @param encoding If non-null, the file's contents should be decoded
* into a string using that encoding. Otherwise, if encoding is null, fetch
* the file's contents as a Uint8Array.
* If no encoding is specified, then the raw buffer is returned.
*/
abstract readFile(fname: string, encoding: BufferEncoding | null, flag: FileFlag, cred: Cred): Promise<FileContents>;
abstract readFile(fname: string, flag: FileFlag, cred: Cred): Promise<Uint8Array>;
/**
* Synchronously reads the entire contents of a file.
* @param encoding If non-null, the file's contents should be decoded
* into a string using that encoding. Otherwise, if encoding is null, fetch
* the file's contents as a Uint8Array.
*/
abstract readFileSync(fname: string, encoding: BufferEncoding | null, flag: FileFlag, cred: Cred): FileContents;
abstract readFileSync(fname: string, flag: FileFlag, cred: Cred): Uint8Array;
/**

@@ -202,3 +194,3 @@ * Asynchronously writes data to a file, replacing the file

*/
abstract writeFile(fname: string, data: FileContents, encoding: BufferEncoding | null, flag: FileFlag, mode: number, cred: Cred): Promise<void>;
abstract writeFile(fname: string, data: Uint8Array, flag: FileFlag, mode: number, cred: Cred): Promise<void>;
/**

@@ -210,3 +202,3 @@ * Synchronously writes data to a file, replacing the file

*/
abstract writeFileSync(fname: string, data: FileContents, encoding: BufferEncoding | null, flag: FileFlag, mode: number, cred: Cred): void;
abstract writeFileSync(fname: string, data: Uint8Array, flag: FileFlag, mode: number, cred: Cred): void;
/**

@@ -216,3 +208,3 @@ * Asynchronously append data to a file, creating the file if

*/
abstract appendFile(fname: string, data: FileContents, encoding: BufferEncoding | null, flag: FileFlag, mode: number, cred: Cred): Promise<void>;
abstract appendFile(fname: string, data: Uint8Array, flag: FileFlag, mode: number, cred: Cred): Promise<void>;
/**

@@ -222,3 +214,3 @@ * Synchronously append data to a file, creating the file if

*/
abstract appendFileSync(fname: string, data: FileContents, encoding: BufferEncoding | null, flag: FileFlag, mode: number, cred: Cred): void;
abstract appendFileSync(fname: string, data: Uint8Array, flag: FileFlag, mode: number, cred: Cred): void;
/**

@@ -334,8 +326,8 @@ * Asynchronous `chmod`.

truncateSync(p: string, len: number, cred: Cred): void;
readFile(fname: string, encoding: BufferEncoding | null, flag: FileFlag, cred: Cred): Promise<FileContents>;
readFileSync(fname: string, encoding: BufferEncoding | null, flag: FileFlag, cred: Cred): FileContents;
writeFile(fname: string, data: FileContents, encoding: BufferEncoding | null, flag: FileFlag, mode: number, cred: Cred): Promise<void>;
writeFileSync(fname: string, data: FileContents, encoding: BufferEncoding | null, flag: FileFlag, mode: number, cred: Cred): void;
appendFile(fname: string, data: FileContents, encoding: BufferEncoding | null, flag: FileFlag, mode: number, cred: Cred): Promise<void>;
appendFileSync(fname: string, data: FileContents, encoding: BufferEncoding | null, flag: FileFlag, mode: number, cred: Cred): void;
readFile(fname: string, flag: FileFlag, cred: Cred): Promise<Uint8Array>;
readFileSync(fname: string, flag: FileFlag, cred: Cred): Uint8Array;
writeFile(fname: string, data: Uint8Array, flag: FileFlag, mode: number, cred: Cred): Promise<void>;
writeFileSync(fname: string, data: Uint8Array, flag: FileFlag, mode: number, cred: Cred): void;
appendFile(fname: string, data: Uint8Array, flag: FileFlag, mode: number, cred: Cred): Promise<void>;
appendFileSync(fname: string, data: Uint8Array, flag: FileFlag, mode: number, cred: Cred): void;
chmod(p: string, mode: number, cred: Cred): Promise<void>;

@@ -342,0 +334,0 @@ chmodSync(p: string, mode: number, cred: Cred): void;

@@ -16,3 +16,3 @@ /* eslint-disable @typescript-eslint/no-unused-vars */

import * as path from './emulation/path.js';
import { decode, encode } from './utils.js';
import { encode } from './utils.js';
/**

@@ -321,3 +321,3 @@ * Structure for a filesystem. **All** ZenFS FileSystems must implement

}
readFile(fname, encoding, flag, cred) {
readFile(fname, flag, cred) {
return __awaiter(this, void 0, void 0, function* () {

@@ -332,6 +332,3 @@ // Get file.

yield fd.close();
if (encoding === null) {
return buf;
}
return decode(buf);
return buf;
}

@@ -343,3 +340,3 @@ finally {

}
readFileSync(fname, encoding, flag, cred) {
readFileSync(fname, flag, cred) {
// Get file.

@@ -353,6 +350,3 @@ const fd = this.openSync(fname, flag, 0o644, cred);

fd.closeSync();
if (encoding === null) {
return buf;
}
return decode(buf);
return buf;
}

@@ -363,3 +357,3 @@ finally {

}
writeFile(fname, data, encoding, flag, mode, cred) {
writeFile(fname, data, flag, mode, cred) {
return __awaiter(this, void 0, void 0, function* () {

@@ -380,3 +374,3 @@ // Get file.

}
writeFileSync(fname, data, encoding, flag, mode, cred) {
writeFileSync(fname, data, flag, mode, cred) {
// Get file.

@@ -395,3 +389,3 @@ const fd = this.openSync(fname, flag, mode, cred);

}
appendFile(fname, data, encoding, flag, mode, cred) {
appendFile(fname, data, flag, mode, cred) {
return __awaiter(this, void 0, void 0, function* () {

@@ -410,3 +404,3 @@ const fd = yield this.open(fname, flag, mode, cred);

}
appendFileSync(fname, data, encoding, flag, mode, cred) {
appendFileSync(fname, data, flag, mode, cred) {
const fd = this.openSync(fname, flag, mode, cred);

@@ -413,0 +407,0 @@ try {

@@ -8,2 +8,3 @@ /// <reference types="node" resolution-mode="require"/>

import type { BaseBackendConstructor } from './backends/backend.js';
import type { TextEncoder as TextEncoderType, TextDecoder as TextDecoderType } from 'node:util';
/**

@@ -34,6 +35,6 @@ * Synchronous recursive makedir.

export declare const ROOT_NODE_ID: string;
export declare const encode: (input?: string) => Uint8Array;
export declare const decode: (input?: ArrayBuffer | NodeJS.ArrayBufferView, options?: {
stream?: boolean;
}) => string;
declare const textEncoder: TextEncoderType;
export declare const encode: typeof textEncoder.encode;
declare const textDecoder: TextDecoderType;
export declare const decode: typeof textDecoder.decode;
/**

@@ -44,1 +45,2 @@ * Generates a random ID.

export declare function randomUUID(): string;
export {};

@@ -215,4 +215,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

export const ROOT_NODE_ID = '/';
export const encode = new globalThis.TextEncoder().encode;
export const decode = new globalThis.TextDecoder().decode;
const textEncoder = new globalThis.TextEncoder();
export const encode = textEncoder.encode.bind(textEncoder);
const textDecoder = new globalThis.TextDecoder();
export const decode = textDecoder.decode.bind(textDecoder);
/**

@@ -219,0 +221,0 @@ * Generates a random ID.

{
"name": "@zenfs/core",
"version": "0.0.11",
"version": "0.0.12",
"description": "A filesystem in your browser",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

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