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

filelist-utils

Package Overview
Dependencies
Maintainers
1
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

filelist-utils - npm Package Compare versions

Comparing version 1.1.1 to 1.2.0

lib-esm/fileCollectionFromPaths.browser.d.ts

3

lib-esm/fileCollectionFromFileList.js

@@ -20,3 +20,4 @@ import { FileCollection } from './FileCollection';

size: file.size,
relativePath: file.webkitRelativePath || file.name,
//@ts-expect-error We allow file.path as alternative to webkitRelativePath
relativePath: file.webkitRelativePath || file.path || file.name,
lastModified: file.lastModified,

@@ -23,0 +24,0 @@ text: () => file.text(),

@@ -19,3 +19,3 @@ import { FileCollection } from './FileCollection';

//@ts-expect-error We allow file.path as alternative to webkitRelativePath
relativePath: file.webkitRelativePath || file.path || '.',
relativePath: file.webkitRelativePath || file.path || file.name,
lastModified: file.lastModified,

@@ -22,0 +22,0 @@ text: () => file.text(),

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

import { createReadStream } from 'node:fs';
import { readdir, stat, readFile } from 'node:fs/promises';
import { basename, join, resolve } from 'node:path';
import { Readable } from 'node:stream';
import { FileCollection } from './FileCollection';
import { maybeExpand } from './utilities/maybeExpand';
import { maybeFilter } from './utilities/maybeFilter';
import { fileCollectionFromPaths } from './fileCollectionFromPaths';
/**

@@ -15,42 +9,4 @@ * Generate a FileCollection from a directory path

export async function fileCollectionFromPath(path, options = {}) {
path = resolve(path);
const base = basename(path);
let fileCollectionItems = [];
await appendFiles(fileCollectionItems, path, base);
fileCollectionItems = await maybeExpand(fileCollectionItems, options);
fileCollectionItems = await maybeFilter(fileCollectionItems, options);
return new FileCollection(fileCollectionItems);
return fileCollectionFromPaths([path], options);
}
async function appendFiles(fileCollection, currentDir, base) {
const entries = await readdir(currentDir);
for (let entry of entries) {
const current = join(currentDir, entry);
const info = await stat(current);
if (info.isDirectory()) {
await appendFiles(fileCollection, current, `${base}/${entry}`);
}
else {
fileCollection.push({
name: entry,
size: info.size,
relativePath: `${base}/${entry}`,
lastModified: Math.round(info.mtimeMs),
text: () => {
return readFile(current, {
encoding: 'utf8',
});
},
arrayBuffer: () => {
return readFile(current);
},
stream: () => {
if (Readable.toWeb) {
return Readable.toWeb(createReadStream(current));
}
throw new Error('The stream() method is only supported in Node.js >= 18.0.0');
},
});
}
}
}
//# sourceMappingURL=fileCollectionFromPath.js.map
export * from './fileCollectionFromPath';
export * from './fileCollectionFromPaths';
export * from './fileCollectionFromZip';

@@ -3,0 +4,0 @@ export * from './fileCollectionFromWebservice';

export * from './fileCollectionFromPath';
export * from './fileCollectionFromPaths';
export * from './fileCollectionFromZip';

@@ -3,0 +4,0 @@ export * from './fileCollectionFromWebservice';

@@ -23,3 +23,4 @@ "use strict";

size: file.size,
relativePath: file.webkitRelativePath || file.name,
//@ts-expect-error We allow file.path as alternative to webkitRelativePath
relativePath: file.webkitRelativePath || file.path || file.name,
lastModified: file.lastModified,

@@ -26,0 +27,0 @@ text: () => file.text(),

@@ -22,3 +22,3 @@ "use strict";

//@ts-expect-error We allow file.path as alternative to webkitRelativePath
relativePath: file.webkitRelativePath || file.path || '.',
relativePath: file.webkitRelativePath || file.path || file.name,
lastModified: file.lastModified,

@@ -25,0 +25,0 @@ text: () => file.text(),

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.fileCollectionFromPath = void 0;
const node_fs_1 = require("node:fs");
const promises_1 = require("node:fs/promises");
const node_path_1 = require("node:path");
const node_stream_1 = require("node:stream");
const FileCollection_1 = require("./FileCollection");
const maybeExpand_1 = require("./utilities/maybeExpand");
const maybeFilter_1 = require("./utilities/maybeFilter");
const fileCollectionFromPaths_1 = require("./fileCollectionFromPaths");
/**

@@ -18,43 +12,5 @@ * Generate a FileCollection from a directory path

async function fileCollectionFromPath(path, options = {}) {
path = (0, node_path_1.resolve)(path);
const base = (0, node_path_1.basename)(path);
let fileCollectionItems = [];
await appendFiles(fileCollectionItems, path, base);
fileCollectionItems = await (0, maybeExpand_1.maybeExpand)(fileCollectionItems, options);
fileCollectionItems = await (0, maybeFilter_1.maybeFilter)(fileCollectionItems, options);
return new FileCollection_1.FileCollection(fileCollectionItems);
return (0, fileCollectionFromPaths_1.fileCollectionFromPaths)([path], options);
}
exports.fileCollectionFromPath = fileCollectionFromPath;
async function appendFiles(fileCollection, currentDir, base) {
const entries = await (0, promises_1.readdir)(currentDir);
for (let entry of entries) {
const current = (0, node_path_1.join)(currentDir, entry);
const info = await (0, promises_1.stat)(current);
if (info.isDirectory()) {
await appendFiles(fileCollection, current, `${base}/${entry}`);
}
else {
fileCollection.push({
name: entry,
size: info.size,
relativePath: `${base}/${entry}`,
lastModified: Math.round(info.mtimeMs),
text: () => {
return (0, promises_1.readFile)(current, {
encoding: 'utf8',
});
},
arrayBuffer: () => {
return (0, promises_1.readFile)(current);
},
stream: () => {
if (node_stream_1.Readable.toWeb) {
return node_stream_1.Readable.toWeb((0, node_fs_1.createReadStream)(current));
}
throw new Error('The stream() method is only supported in Node.js >= 18.0.0');
},
});
}
}
}
//# sourceMappingURL=fileCollectionFromPath.js.map
export * from './fileCollectionFromPath';
export * from './fileCollectionFromPaths';
export * from './fileCollectionFromZip';

@@ -3,0 +4,0 @@ export * from './fileCollectionFromWebservice';

@@ -18,2 +18,3 @@ "use strict";

__exportStar(require("./fileCollectionFromPath"), exports);
__exportStar(require("./fileCollectionFromPaths"), exports);
__exportStar(require("./fileCollectionFromZip"), exports);

@@ -20,0 +21,0 @@ __exportStar(require("./fileCollectionFromWebservice"), exports);

{
"name": "filelist-utils",
"version": "1.1.1",
"version": "1.2.0",
"description": "Create a FileCollection from a path or a zip file",

@@ -10,4 +10,6 @@ "main": "./lib/index.js",

"./lib-esm/fileCollectionFromPath.js": "./lib-esm/fileCollectionFromPath.browser.js",
"./lib-esm/fileCollectionFromPaths.js": "./lib-esm/fileCollectionFromPaths.browser.js",
"./lib-esm/ungzipStream.js": "./lib-esm/ungzipStream.browser.js",
"./lib/fileCollectionFromPath.js": "./lib/fileCollectionFromPath.browser.js",
"./lib/fileCollectionFromPaths.js": "./lib/fileCollectionFromPaths.browser.js",
"./lib/ungzipStream.js": "./lib/ungzipStream.browser.js"

@@ -14,0 +16,0 @@ },

@@ -27,3 +27,4 @@ import { ExpandOptions } from './ExpandOptions';

size: file.size,
relativePath: file.webkitRelativePath || file.name,
//@ts-expect-error We allow file.path as alternative to webkitRelativePath
relativePath: file.webkitRelativePath || file.path || file.name,
lastModified: file.lastModified,

@@ -30,0 +31,0 @@ text: () => file.text(),

@@ -26,3 +26,3 @@ import { ExpandOptions } from './ExpandOptions';

//@ts-expect-error We allow file.path as alternative to webkitRelativePath
relativePath: file.webkitRelativePath || file.path || '.',
relativePath: file.webkitRelativePath || file.path || file.name,
lastModified: file.lastModified,

@@ -29,0 +29,0 @@ text: () => file.text(),

@@ -1,11 +0,5 @@

import { createReadStream } from 'node:fs';
import { readdir, stat, readFile } from 'node:fs/promises';
import { basename, join, resolve } from 'node:path';
import { Readable } from 'node:stream';
import { ExpandOptions } from './ExpandOptions';
import { FileCollection } from './FileCollection';
import { FileCollectionItem } from './FileCollectionItem';
import { maybeExpand } from './utilities/maybeExpand';
import { FilterOptions, maybeFilter } from './utilities/maybeFilter';
import { fileCollectionFromPaths } from './fileCollectionFromPaths';
import { FilterOptions } from './utilities/maybeFilter';

@@ -22,48 +16,3 @@ /**

): Promise<FileCollection> {
path = resolve(path);
const base = basename(path);
let fileCollectionItems: FileCollectionItem[] = [];
await appendFiles(fileCollectionItems, path, base);
fileCollectionItems = await maybeExpand(fileCollectionItems, options);
fileCollectionItems = await maybeFilter(fileCollectionItems, options);
return new FileCollection(fileCollectionItems);
return fileCollectionFromPaths([path], options);
}
async function appendFiles(
fileCollection: FileCollectionItem[],
currentDir: string,
base: string,
) {
const entries = await readdir(currentDir);
for (let entry of entries) {
const current = join(currentDir, entry);
const info = await stat(current);
if (info.isDirectory()) {
await appendFiles(fileCollection, current, `${base}/${entry}`);
} else {
fileCollection.push({
name: entry,
size: info.size,
relativePath: `${base}/${entry}`,
lastModified: Math.round(info.mtimeMs),
text: (): Promise<string> => {
return readFile(current, {
encoding: 'utf8',
});
},
arrayBuffer: (): Promise<ArrayBuffer> => {
return readFile(current);
},
stream: (): ReadableStream => {
if (Readable.toWeb) {
return Readable.toWeb(createReadStream(current));
}
throw new Error(
'The stream() method is only supported in Node.js >= 18.0.0',
);
},
});
}
}
}
export * from './fileCollectionFromPath';
export * from './fileCollectionFromPaths';
export * from './fileCollectionFromZip';

@@ -3,0 +4,0 @@ export * from './fileCollectionFromWebservice';

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

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

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