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

@spinajs/fs

Package Overview
Dependencies
Maintainers
1
Versions
260
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@spinajs/fs - npm Package Compare versions

Comparing version 2.0.301 to 2.0.302

50

lib/cjs/interfaces.d.ts

@@ -9,2 +9,10 @@ /// <reference types="node" />

import { PassThrough } from 'stream';
/**
* Class for handling fs URI eg. fs://fs-temp/path/to/file
*/
export declare class URI {
Fs: fs;
Path: string;
constructor(uri: string);
}
export interface IProviderConfiguration {

@@ -189,3 +197,3 @@ name: string;

*/
static download(path: string): Promise<string>;
static download(path: URI): Promise<string>;
/**

@@ -197,3 +205,3 @@ * Copies local file into fs

*/
static upload(srcPath: string, destPath?: string): Promise<void>;
static upload(srcPath: string, destPath?: URI): Promise<void>;
/**

@@ -206,3 +214,3 @@ *

*/
static hash(path: string, algo?: string): Promise<string>;
static hash(path: URI, algo?: string): Promise<string>;
/**

@@ -214,18 +222,18 @@ *

*/
static resolvePath(path: string): string;
static read(path: string, encoding?: BufferEncoding): Promise<string | Buffer>;
static readStream(path: string, encoding?: BufferEncoding): Promise<NodeJS.ReadableStream>;
static write(path: string, data: string | Uint8Array, encoding?: BufferEncoding): Promise<void>;
static writeStream(path: string, encoding?: BufferEncoding): Promise<WriteStream | PassThrough>;
static exists(path: string): Promise<boolean>;
static dirExists(path: string): Promise<boolean>;
static copy(path: string, dest: string, dstFs?: fs): Promise<void>;
static move(oldPath: string, newPath: string, dstFs?: fs): Promise<void>;
static rename(oldPath: string, newPath: string): Promise<void>;
static rm(path: string): Promise<void>;
static mkdir(path: string): Promise<void>;
static stat(path: string): Promise<IStat>;
static list(path: string): Promise<string[]>;
static resolvePath(path: URI): string;
static read(path: URI, encoding?: BufferEncoding): Promise<string | Buffer>;
static readStream(path: URI, encoding?: BufferEncoding): Promise<NodeJS.ReadableStream>;
static write(path: URI, data: string | Uint8Array, encoding?: BufferEncoding): Promise<void>;
static writeStream(path: URI, encoding?: BufferEncoding): Promise<WriteStream | PassThrough>;
static exists(path: URI): Promise<boolean>;
static dirExists(path: URI): Promise<boolean>;
static copy(src: URI, dest: URI): Promise<void>;
static move(src: URI, dest: URI): Promise<void>;
static rename(src: URI, dest: URI | string): Promise<void>;
static rm(path: URI): Promise<void>;
static mkdir(path: URI): Promise<void>;
static stat(path: URI): Promise<IStat>;
static list(path: URI): Promise<string[]>;
static tmppath(fs: string): string;
static append(path: string, data: string | Uint8Array, encoding?: BufferEncoding): Promise<void>;
static append(path: URI, data: string | Uint8Array, encoding?: BufferEncoding): Promise<void>;
/**

@@ -239,3 +247,3 @@ *

*/
static zip(path: string | string[], dstFile?: string, dstFs?: fs): Promise<IZipResult>;
static zip(path: URI | URI[], dstFile: URI): Promise<IZipResult>;
/**

@@ -249,3 +257,3 @@ * Decompress given file to destination path

*/
static unzip(srcPath: string, destPath?: string, dstFs?: fs): Promise<string>;
static unzip(srcPath: URI, destPath: URI): Promise<string>;
/**

@@ -257,3 +265,3 @@ *

*/
static isDir(path: string): Promise<boolean>;
static isDir(path: URI): Promise<boolean>;
}

@@ -260,0 +268,0 @@ /**

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FileHasher = exports.FileInfoService = exports.fs = void 0;
exports.FileHasher = exports.FileInfoService = exports.fs = exports.URI = void 0;
/* eslint-disable security/detect-non-literal-fs-filename */

@@ -8,16 +8,21 @@ const di_1 = require("@spinajs/di");

const uuid_1 = require("uuid");
function uriToFs(path) {
const reg = /^(fs+:\/\/)+(.+)$/gm;
if (!reg.test(path)) {
return [null, path];
/**
* Class for handling fs URI eg. fs://fs-temp/path/to/file
*/
class URI {
constructor(uri) {
const reg = /^(fs+:\/\/)+(.+)$/gm;
if (!reg.test(uri)) {
throw new exceptions_1.InvalidArgument(`URI ${uri} is not valid`);
}
const args = reg.exec(uri)[2].split('/');
const fsName = args[0];
this.Path = args[1];
this.Fs = di_1.DI.resolve('__file_provider__', [fsName]);
if (!this.Fs) {
throw new exceptions_1.InvalidArgument(`Filesystem ${fsName} not registered, check your fs configuration !`);
}
}
const args = reg.exec(path)[2].split('/');
const fsName = args[0];
const fPath = args[1];
const f = di_1.DI.resolve('__file_provider__', [fsName]);
if (!f) {
throw new exceptions_1.IOFail(`Filesystem ${fsName} not registered, check your fs configuration !`);
}
return [f, fPath];
}
exports.URI = URI;
class fs extends di_1.AsyncService {

@@ -69,4 +74,3 @@ get ServiceName() {

static download(path) {
const [fs, p] = uriToFs(path);
return fs.download(p);
return path.Fs.download(path.Path);
}

@@ -80,4 +84,3 @@ /**

static upload(srcPath, destPath) {
const [fs, p] = uriToFs(destPath);
return fs.upload(srcPath, p);
return destPath.Fs.upload(srcPath, destPath.Path);
}

@@ -92,4 +95,3 @@ /**

static hash(path, algo) {
const [fs, p] = uriToFs(path);
return fs.hash(p, algo);
return path.Fs.hash(path.Path, algo);
}

@@ -103,59 +105,42 @@ /**

static resolvePath(path) {
const [fs, p] = uriToFs(path);
return fs.resolvePath(p);
return path.Fs.resolvePath(path.Path);
}
static read(path, encoding) {
const [fs, p] = uriToFs(path);
return fs.read(p, encoding);
return path.Fs.read(path.Path, encoding);
}
static readStream(path, encoding) {
const [fs, p] = uriToFs(path);
return fs.readStream(p, encoding);
return path.Fs.readStream(path.Path, encoding);
}
static write(path, data, encoding) {
const [fs, p] = uriToFs(path);
return fs.write(p, data, encoding);
return path.Fs.write(path.Path, data, encoding);
}
static writeStream(path, readStream, encoding) {
const [fs, p] = uriToFs(path);
return fs.writeStream(p, readStream, encoding);
return path.Fs.writeStream(path.Path, readStream, encoding);
}
static exists(path) {
const [fs, p] = uriToFs(path);
return fs.exists(p);
return path.Fs.exists(path.Path);
}
static dirExists(path) {
const [fs, p] = uriToFs(path);
return fs.dirExists(p);
return path.Fs.dirExists(path.Path);
}
static copy(path, dest, dstFs) {
const [fs, p] = uriToFs(path);
const [dFs, dP] = uriToFs(dest);
return fs.copy(p, dP, dFs ?? dstFs);
static copy(src, dest) {
return src.Fs.copy(src.Path, dest.Path, dest.Fs);
}
static move(oldPath, newPath, dstFs) {
const [fs, p] = uriToFs(oldPath);
const [dFs, dP] = uriToFs(newPath);
return fs.move(p, dP, dFs ?? dstFs);
static move(src, dest) {
return src.Fs.move(src.Path, dest.Path, dest.Fs);
}
static rename(oldPath, newPath) {
const [fs, p] = uriToFs(oldPath);
const [, p2] = uriToFs(newPath);
return fs.rename(p, p2);
static rename(src, dest) {
return src.Fs.rename(src.Path, dest instanceof URI ? dest.Path : dest);
}
static rm(path) {
const [fs, p] = uriToFs(path);
return fs.rm(p);
return path.Fs.rm(path.Path);
}
static mkdir(path) {
const [fs, p] = uriToFs(path);
return fs.mkdir(p);
return path.Fs.mkdir(path.Path);
}
static stat(path) {
const [fs, p] = uriToFs(path);
return fs.stat(p);
return path.Fs.stat(path.Path);
}
static list(path) {
const [fs, p] = uriToFs(path);
return fs.list(p);
return path.Fs.list(path.Path);
}

@@ -170,4 +155,3 @@ static tmppath(fs) {

static append(path, data, encoding) {
const [fs, p] = uriToFs(path);
return fs.append(p, data, encoding);
return path.Fs.append(path.Path, data, encoding);
}

@@ -182,7 +166,6 @@ /**

*/
static zip(path, dstFile, dstFs) {
const [fs] = !Array.isArray(path) ? uriToFs(path) : uriToFs(path[0]);
const [dFs, fP] = uriToFs(dstFile);
const files = Array.isArray(path) ? path.map((x) => uriToFs(x)[1]) : uriToFs(path)[1];
return fs.zip(files, dFs ?? dstFs, fP ?? dstFile);
static zip(path, dstFile) {
const fs = !Array.isArray(path) ? path.Fs : path[0].Fs;
const files = Array.isArray(path) ? path.map(x => x.Path) : path.Path;
return fs.zip(files, dstFile.Fs, dstFile.Path);
}

@@ -197,6 +180,4 @@ /**

*/
static unzip(srcPath, destPath, dstFs) {
const [fs, p] = uriToFs(srcPath);
const [dFs, fP] = uriToFs(destPath);
return fs.unzip(p, fP, dFs ?? dstFs);
static unzip(srcPath, destPath) {
return srcPath.Fs.unzip(srcPath.Path, destPath.Path, destPath.Fs);
}

@@ -210,4 +191,3 @@ /**

static isDir(path) {
const [fs, p] = uriToFs(path);
return fs.isDir(p);
return path.Fs.isDir(path.Path);
}

@@ -214,0 +194,0 @@ }

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

import { PassThrough } from 'stream';
/**
* Class for handling fs URI eg. fs://fs-temp/path/to/file
*/
export declare class URI {
Fs: fs;
Path: string;
constructor(uri: string);
}
export interface IProviderConfiguration {

@@ -189,3 +197,3 @@ name: string;

*/
static download(path: string): Promise<string>;
static download(path: URI): Promise<string>;
/**

@@ -197,3 +205,3 @@ * Copies local file into fs

*/
static upload(srcPath: string, destPath?: string): Promise<void>;
static upload(srcPath: string, destPath?: URI): Promise<void>;
/**

@@ -206,3 +214,3 @@ *

*/
static hash(path: string, algo?: string): Promise<string>;
static hash(path: URI, algo?: string): Promise<string>;
/**

@@ -214,18 +222,18 @@ *

*/
static resolvePath(path: string): string;
static read(path: string, encoding?: BufferEncoding): Promise<string | Buffer>;
static readStream(path: string, encoding?: BufferEncoding): Promise<NodeJS.ReadableStream>;
static write(path: string, data: string | Uint8Array, encoding?: BufferEncoding): Promise<void>;
static writeStream(path: string, encoding?: BufferEncoding): Promise<WriteStream | PassThrough>;
static exists(path: string): Promise<boolean>;
static dirExists(path: string): Promise<boolean>;
static copy(path: string, dest: string, dstFs?: fs): Promise<void>;
static move(oldPath: string, newPath: string, dstFs?: fs): Promise<void>;
static rename(oldPath: string, newPath: string): Promise<void>;
static rm(path: string): Promise<void>;
static mkdir(path: string): Promise<void>;
static stat(path: string): Promise<IStat>;
static list(path: string): Promise<string[]>;
static resolvePath(path: URI): string;
static read(path: URI, encoding?: BufferEncoding): Promise<string | Buffer>;
static readStream(path: URI, encoding?: BufferEncoding): Promise<NodeJS.ReadableStream>;
static write(path: URI, data: string | Uint8Array, encoding?: BufferEncoding): Promise<void>;
static writeStream(path: URI, encoding?: BufferEncoding): Promise<WriteStream | PassThrough>;
static exists(path: URI): Promise<boolean>;
static dirExists(path: URI): Promise<boolean>;
static copy(src: URI, dest: URI): Promise<void>;
static move(src: URI, dest: URI): Promise<void>;
static rename(src: URI, dest: URI | string): Promise<void>;
static rm(path: URI): Promise<void>;
static mkdir(path: URI): Promise<void>;
static stat(path: URI): Promise<IStat>;
static list(path: URI): Promise<string[]>;
static tmppath(fs: string): string;
static append(path: string, data: string | Uint8Array, encoding?: BufferEncoding): Promise<void>;
static append(path: URI, data: string | Uint8Array, encoding?: BufferEncoding): Promise<void>;
/**

@@ -239,3 +247,3 @@ *

*/
static zip(path: string | string[], dstFile?: string, dstFs?: fs): Promise<IZipResult>;
static zip(path: URI | URI[], dstFile: URI): Promise<IZipResult>;
/**

@@ -249,3 +257,3 @@ * Decompress given file to destination path

*/
static unzip(srcPath: string, destPath?: string, dstFs?: fs): Promise<string>;
static unzip(srcPath: URI, destPath: URI): Promise<string>;
/**

@@ -257,3 +265,3 @@ *

*/
static isDir(path: string): Promise<boolean>;
static isDir(path: URI): Promise<boolean>;
}

@@ -260,0 +268,0 @@ /**

/* eslint-disable security/detect-non-literal-fs-filename */
import { AsyncService, DI } from '@spinajs/di';
import { IOFail } from '@spinajs/exceptions';
import { InvalidArgument, IOFail } from '@spinajs/exceptions';
import { v4 as uuidv4 } from 'uuid';
function uriToFs(path) {
const reg = /^(fs+:\/\/)+(.+)$/gm;
if (!reg.test(path)) {
return [null, path];
/**
* Class for handling fs URI eg. fs://fs-temp/path/to/file
*/
export class URI {
constructor(uri) {
const reg = /^(fs+:\/\/)+(.+)$/gm;
if (!reg.test(uri)) {
throw new InvalidArgument(`URI ${uri} is not valid`);
}
const args = reg.exec(uri)[2].split('/');
const fsName = args[0];
this.Path = args[1];
this.Fs = DI.resolve('__file_provider__', [fsName]);
if (!this.Fs) {
throw new InvalidArgument(`Filesystem ${fsName} not registered, check your fs configuration !`);
}
}
const args = reg.exec(path)[2].split('/');
const fsName = args[0];
const fPath = args[1];
const f = DI.resolve('__file_provider__', [fsName]);
if (!f) {
throw new IOFail(`Filesystem ${fsName} not registered, check your fs configuration !`);
}
return [f, fPath];
}

@@ -65,4 +69,3 @@ export class fs extends AsyncService {

static download(path) {
const [fs, p] = uriToFs(path);
return fs.download(p);
return path.Fs.download(path.Path);
}

@@ -76,4 +79,3 @@ /**

static upload(srcPath, destPath) {
const [fs, p] = uriToFs(destPath);
return fs.upload(srcPath, p);
return destPath.Fs.upload(srcPath, destPath.Path);
}

@@ -88,4 +90,3 @@ /**

static hash(path, algo) {
const [fs, p] = uriToFs(path);
return fs.hash(p, algo);
return path.Fs.hash(path.Path, algo);
}

@@ -99,59 +100,42 @@ /**

static resolvePath(path) {
const [fs, p] = uriToFs(path);
return fs.resolvePath(p);
return path.Fs.resolvePath(path.Path);
}
static read(path, encoding) {
const [fs, p] = uriToFs(path);
return fs.read(p, encoding);
return path.Fs.read(path.Path, encoding);
}
static readStream(path, encoding) {
const [fs, p] = uriToFs(path);
return fs.readStream(p, encoding);
return path.Fs.readStream(path.Path, encoding);
}
static write(path, data, encoding) {
const [fs, p] = uriToFs(path);
return fs.write(p, data, encoding);
return path.Fs.write(path.Path, data, encoding);
}
static writeStream(path, readStream, encoding) {
const [fs, p] = uriToFs(path);
return fs.writeStream(p, readStream, encoding);
return path.Fs.writeStream(path.Path, readStream, encoding);
}
static exists(path) {
const [fs, p] = uriToFs(path);
return fs.exists(p);
return path.Fs.exists(path.Path);
}
static dirExists(path) {
const [fs, p] = uriToFs(path);
return fs.dirExists(p);
return path.Fs.dirExists(path.Path);
}
static copy(path, dest, dstFs) {
const [fs, p] = uriToFs(path);
const [dFs, dP] = uriToFs(dest);
return fs.copy(p, dP, dFs ?? dstFs);
static copy(src, dest) {
return src.Fs.copy(src.Path, dest.Path, dest.Fs);
}
static move(oldPath, newPath, dstFs) {
const [fs, p] = uriToFs(oldPath);
const [dFs, dP] = uriToFs(newPath);
return fs.move(p, dP, dFs ?? dstFs);
static move(src, dest) {
return src.Fs.move(src.Path, dest.Path, dest.Fs);
}
static rename(oldPath, newPath) {
const [fs, p] = uriToFs(oldPath);
const [, p2] = uriToFs(newPath);
return fs.rename(p, p2);
static rename(src, dest) {
return src.Fs.rename(src.Path, dest instanceof URI ? dest.Path : dest);
}
static rm(path) {
const [fs, p] = uriToFs(path);
return fs.rm(p);
return path.Fs.rm(path.Path);
}
static mkdir(path) {
const [fs, p] = uriToFs(path);
return fs.mkdir(p);
return path.Fs.mkdir(path.Path);
}
static stat(path) {
const [fs, p] = uriToFs(path);
return fs.stat(p);
return path.Fs.stat(path.Path);
}
static list(path) {
const [fs, p] = uriToFs(path);
return fs.list(p);
return path.Fs.list(path.Path);
}

@@ -166,4 +150,3 @@ static tmppath(fs) {

static append(path, data, encoding) {
const [fs, p] = uriToFs(path);
return fs.append(p, data, encoding);
return path.Fs.append(path.Path, data, encoding);
}

@@ -178,7 +161,6 @@ /**

*/
static zip(path, dstFile, dstFs) {
const [fs] = !Array.isArray(path) ? uriToFs(path) : uriToFs(path[0]);
const [dFs, fP] = uriToFs(dstFile);
const files = Array.isArray(path) ? path.map((x) => uriToFs(x)[1]) : uriToFs(path)[1];
return fs.zip(files, dFs ?? dstFs, fP ?? dstFile);
static zip(path, dstFile) {
const fs = !Array.isArray(path) ? path.Fs : path[0].Fs;
const files = Array.isArray(path) ? path.map(x => x.Path) : path.Path;
return fs.zip(files, dstFile.Fs, dstFile.Path);
}

@@ -193,6 +175,4 @@ /**

*/
static unzip(srcPath, destPath, dstFs) {
const [fs, p] = uriToFs(srcPath);
const [dFs, fP] = uriToFs(destPath);
return fs.unzip(p, fP, dFs ?? dstFs);
static unzip(srcPath, destPath) {
return srcPath.Fs.unzip(srcPath.Path, destPath.Path, destPath.Fs);
}

@@ -206,4 +186,3 @@ /**

static isDir(path) {
const [fs, p] = uriToFs(path);
return fs.isDir(p);
return path.Fs.isDir(path.Path);
}

@@ -210,0 +189,0 @@ }

{
"name": "@spinajs/fs",
"version": "2.0.301",
"version": "2.0.302",
"description": "wrapper for file operations",

@@ -55,5 +55,5 @@ "main": "lib/cjs/index.js",

"dependencies": {
"@spinajs/exceptions": "2.0.301",
"@spinajs/util": "2.0.301",
"@spinajs/log-common": "2.0.301",
"@spinajs/exceptions": "2.0.302",
"@spinajs/util": "2.0.302",
"@spinajs/log-common": "2.0.302",
"archiver": "^5.3.1",

@@ -60,0 +60,0 @@ "lodash": "^4.17.21",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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