New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.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.5.1 to 1.6.0-pre.1675462420

lib-esm/fileCollectionToZip.d.ts

2

lib-esm/ExpandOptions.d.ts

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

export declare type ExpandOptions = {
export type ExpandOptions = {
/**

@@ -3,0 +3,0 @@ * Expand all zip files

import { FileCollectionItem } from './FileCollectionItem';
import { FileCollectionItemsZipOptions } from './fileCollectionItemsZip';
export declare class FileCollection {

@@ -11,6 +10,16 @@ readonly files: FileCollectionItem[];

* is the zipped file (called by default 'file.zip')
* Not sure this is super useful and we should probably remove it and replace it by fileCollectionToZip
*/
zip(options?: FileCollectionItemsZipOptions): Promise<FileCollection>;
zip(): Promise<Uint8Array>;
addText(relativePath: string, text: string, options?: {
dateModified?: number;
}): void;
addArrayBuffer(relativePath: string, arrayBuffer: ArrayBuffer, options?: {
dateModified?: number;
}): void;
addTypedArray(relativePath: string, typedArray: Uint8Array, options?: {
dateModified?: number;
}): void;
[Symbol.iterator](): IterableIterator<FileCollectionItem>;
}
//# sourceMappingURL=FileCollection.d.ts.map

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

import { fileCollectionItemsZip, } from './fileCollectionItemsZip';
import { fileCollectionToZip } from './fileCollectionToZip';
export class FileCollection {

@@ -13,8 +13,16 @@ constructor(files) {

* is the zipped file (called by default 'file.zip')
* Not sure this is super useful and we should probably remove it and replace it by fileCollectionToZip
*/
async zip(options = {}) {
return new FileCollection([
await fileCollectionItemsZip(this.files, options),
]);
async zip() {
return fileCollectionToZip(this);
}
addText(relativePath, text, options = {}) {
this.files.push(getItemFromText(relativePath, text, options));
}
addArrayBuffer(relativePath, arrayBuffer, options = {}) {
this.files.push(getItemFromArrayBuffer(relativePath, arrayBuffer, options));
}
addTypedArray(relativePath, typedArray, options = {}) {
this.files.push(getItemFromTypedArray(relativePath, typedArray, options));
}
[Symbol.iterator]() {

@@ -24,2 +32,43 @@ return this.files.values();

}
function getItemFromText(relativePath, text, options = {}) {
const encoder = new TextEncoder();
const data = encoder.encode(text);
return {
relativePath,
name: relativePath.split('/').pop(),
lastModified: options.dateModified || Date.now(),
size: data.length,
text: async () => {
return text;
},
arrayBuffer: async () => {
return data.buffer;
},
stream: () => {
throw new Error('stream no implemented');
},
};
}
function getItemFromArrayBuffer(relativePath, arrayBuffer, options = {}) {
const decoder = new TextDecoder();
const text = decoder.decode(arrayBuffer);
return {
relativePath,
name: relativePath.split('/').pop(),
lastModified: options.dateModified || Date.now(),
size: arrayBuffer.byteLength,
text: async () => {
return text;
},
arrayBuffer: async () => {
return arrayBuffer;
},
stream: () => {
throw new Error('stream no implemented');
},
};
}
function getItemFromTypedArray(relativePath, typedArray, options = {}) {
return getItemFromArrayBuffer(relativePath, typedArray.buffer, options);
}
//# sourceMappingURL=FileCollection.js.map

@@ -51,2 +51,3 @@ import { createReadStream } from 'node:fs';

if (Readable.toWeb) {
//@ts-expect-error todo should be fixed
return Readable.toWeb(createReadStream(current));

@@ -53,0 +54,0 @@ }

import JSZip from 'jszip';
import { FileCollection } from './FileCollection';
export declare type ZipFileContent = Parameters<typeof JSZip.loadAsync>[0];
import { FileCollectionItem } from './FileCollectionItem';
import { FilterOptions } from './utilities/maybeFilter';
export type ZipFileContent = Parameters<typeof JSZip.loadAsync>[0];
/**

@@ -9,3 +11,4 @@ * Create a FileCollection from a zip

*/
export declare function fileCollectionFromZip(zipContent: ZipFileContent): Promise<FileCollection>;
export declare function fileCollectionFromZip(zipContent: ZipFileContent, options?: FilterOptions): Promise<FileCollection>;
export declare function fileCollectionItemsFromZip(zipContent: ZipFileContent): Promise<FileCollectionItem[]>;
//# sourceMappingURL=fileCollectionFromZip.d.ts.map
import JSZip from 'jszip';
import { FileCollection } from './FileCollection';
import { maybeFilter } from './utilities/maybeFilter';
/**

@@ -8,6 +9,11 @@ * Create a FileCollection from a zip

*/
export async function fileCollectionFromZip(zipContent) {
export async function fileCollectionFromZip(zipContent, options = {}) {
let fileCollectionItems = await fileCollectionItemsFromZip(zipContent);
fileCollectionItems = await maybeFilter(fileCollectionItems, options);
return new FileCollection(fileCollectionItems);
}
export async function fileCollectionItemsFromZip(zipContent) {
const jsZip = new JSZip();
const zip = await jsZip.loadAsync(zipContent);
const fileCollectionItems = [];
let fileCollectionItems = [];
for (let key in zip.files) {

@@ -43,4 +49,4 @@ const entry = zip.files[key];

}
return new FileCollection(fileCollectionItems);
return fileCollectionItems;
}
//# sourceMappingURL=fileCollectionFromZip.js.map
import fetch from 'cross-fetch';
import { fileCollectionFromZip } from './fileCollectionFromZip';
import { FileCollection } from './FileCollection';
import { fileCollectionItemsFromZip } from './fileCollectionFromZip';
/**

@@ -10,5 +11,5 @@ * Create a FileCollection from a zip

const response = await fetch(url);
const arrayBuffer = await response.arrayBuffer();
return fileCollectionFromZip(arrayBuffer);
const filecollectionItem = await fileCollectionItemsFromZip(await response.arrayBuffer());
return new FileCollection(filecollectionItem);
}
//# sourceMappingURL=fileCollectionFromZipURL.js.map
import { FileCollectionItem } from './FileCollectionItem';
import { FilterOptions } from './utilities/maybeFilter';
/**

@@ -17,3 +18,3 @@ * Some files in the fileCollectionItems may actually be gzip. This method will ungzip those files.

gzipExtensions?: string[];
}): Promise<FileCollectionItem[]>;
} & FilterOptions): Promise<FileCollectionItem[]>;
//# sourceMappingURL=fileCollectionItemsUngzip.d.ts.map
import { ungzip } from 'pako';
import { ungzipStream } from './ungzipStream';
import { maybeFilter } from './utilities/maybeFilter';
/**

@@ -40,2 +41,3 @@ * Some files in the fileCollectionItems may actually be gzip. This method will ungzip those files.

},
//@ts-expect-error todo should be fixed
stream: () => {

@@ -48,3 +50,3 @@ return ungzipStream(file);

}
return fileCollectionItems.sort((a, b) => a.relativePath < b.relativePath ? -1 : 1);
return maybeFilter(fileCollectionItems.sort((a, b) => a.relativePath < b.relativePath ? -1 : 1), options);
}

@@ -51,0 +53,0 @@ async function isGzip(file) {

import { FileCollectionItem } from './FileCollectionItem';
import { FilterOptions } from './utilities/maybeFilter';
/**

@@ -17,3 +18,3 @@ * Some files in the fileCollectionItems may actually be zip. This method will unzip those files.

zipExtensions?: string[];
}): Promise<FileCollectionItem[]>;
} & FilterOptions): Promise<FileCollectionItem[]>;
//# sourceMappingURL=fileCollectionItemsUnzip.d.ts.map

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

import { fileCollectionFromZip } from './fileCollectionFromZip';
import { fileCollectionItemsFromZip } from './fileCollectionFromZip';
/**

@@ -23,4 +23,4 @@ * Some files in the fileCollectionItems may actually be zip. This method will unzip those files.

}
const zipFileCollection = await fileCollectionFromZip(await file.arrayBuffer());
for (let zipEntry of zipFileCollection) {
const zipFileCollectionItems = await fileCollectionItemsFromZip(await file.arrayBuffer());
for (let zipEntry of zipFileCollectionItems) {
zipEntry.relativePath = `${file.relativePath}/${zipEntry.relativePath}`;

@@ -27,0 +27,0 @@ fileCollectionItems.push(zipEntry);

import { FileCollection } from './FileCollection';
import { FileCollectionItem } from './FileCollectionItem';
export declare type StringObject = Record<string, string>;
declare type GroupByOption = 'baseDir' | 'extension' | 'filename' | ((file?: FileCollectionItem, fileInfo?: ReturnType<typeof getFileInfo>) => string);
export type StringObject = Record<string, string>;
type GroupByOption = 'baseDir' | 'extension' | 'filename' | ((file?: FileCollectionItem, fileInfo?: ReturnType<typeof getFileInfo>) => string);
interface GroupOfFileCollection {

@@ -6,0 +6,0 @@ meta: StringObject;

export * from './fileCollectionFromPath';
export * from './fileCollectionFromPaths';
export * from './fileCollectionFromZip';
export { fileCollectionFromZip } from './fileCollectionFromZip';
export * from './fileCollectionFromZipURL';

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

export * from './fileCollectionFromPath';
export * from './fileCollectionFromPaths';
export * from './fileCollectionFromZip';
export { fileCollectionFromZip } from './fileCollectionFromZip';
export * from './fileCollectionFromZipURL';

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

import { ExpandOptions } from '../ExpandOptions';
import { FileCollectionItem } from '../FileCollectionItem';
import { FilterOptions } from './maybeFilter';
/**

@@ -9,3 +10,3 @@ * Utility function that allows to expand gzip and zip files without really expanding them

*/
export declare function maybeExpand(fileCollectionItems: FileCollectionItem[], options: ExpandOptions): Promise<FileCollectionItem[]>;
export declare function maybeExpand(fileCollectionItems: FileCollectionItem[], options: ExpandOptions & FilterOptions): Promise<FileCollectionItem[]>;
//# sourceMappingURL=maybeExpand.d.ts.map

@@ -10,7 +10,13 @@ import { fileCollectionItemsUngzip } from '../fileCollectionItemsUngzip';

export async function maybeExpand(fileCollectionItems, options) {
const { unzip = {}, ungzip = {} } = options;
fileCollectionItems = await fileCollectionItemsUnzip(fileCollectionItems, unzip);
fileCollectionItems = await fileCollectionItemsUngzip(fileCollectionItems, ungzip);
const { unzip = {}, ungzip = {}, ...res } = options;
fileCollectionItems = await fileCollectionItemsUnzip(fileCollectionItems, {
...unzip,
...res,
});
fileCollectionItems = await fileCollectionItemsUngzip(fileCollectionItems, {
...ungzip,
...res,
});
return fileCollectionItems;
}
//# sourceMappingURL=maybeExpand.js.map
import { FileCollectionItem } from '../FileCollectionItem';
export declare type FilterOptions = {
export type FilterOptions = {
/**

@@ -4,0 +4,0 @@ * Should we ignored files starting with dot

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

export declare type ExpandOptions = {
export type ExpandOptions = {
/**

@@ -3,0 +3,0 @@ * Expand all zip files

import { FileCollectionItem } from './FileCollectionItem';
import { FileCollectionItemsZipOptions } from './fileCollectionItemsZip';
export declare class FileCollection {

@@ -11,6 +10,16 @@ readonly files: FileCollectionItem[];

* is the zipped file (called by default 'file.zip')
* Not sure this is super useful and we should probably remove it and replace it by fileCollectionToZip
*/
zip(options?: FileCollectionItemsZipOptions): Promise<FileCollection>;
zip(): Promise<Uint8Array>;
addText(relativePath: string, text: string, options?: {
dateModified?: number;
}): void;
addArrayBuffer(relativePath: string, arrayBuffer: ArrayBuffer, options?: {
dateModified?: number;
}): void;
addTypedArray(relativePath: string, typedArray: Uint8Array, options?: {
dateModified?: number;
}): void;
[Symbol.iterator](): IterableIterator<FileCollectionItem>;
}
//# sourceMappingURL=FileCollection.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FileCollection = void 0;
const fileCollectionItemsZip_1 = require("./fileCollectionItemsZip");
const fileCollectionToZip_1 = require("./fileCollectionToZip");
class FileCollection {

@@ -16,8 +16,16 @@ constructor(files) {

* is the zipped file (called by default 'file.zip')
* Not sure this is super useful and we should probably remove it and replace it by fileCollectionToZip
*/
async zip(options = {}) {
return new FileCollection([
await (0, fileCollectionItemsZip_1.fileCollectionItemsZip)(this.files, options),
]);
async zip() {
return (0, fileCollectionToZip_1.fileCollectionToZip)(this);
}
addText(relativePath, text, options = {}) {
this.files.push(getItemFromText(relativePath, text, options));
}
addArrayBuffer(relativePath, arrayBuffer, options = {}) {
this.files.push(getItemFromArrayBuffer(relativePath, arrayBuffer, options));
}
addTypedArray(relativePath, typedArray, options = {}) {
this.files.push(getItemFromTypedArray(relativePath, typedArray, options));
}
[Symbol.iterator]() {

@@ -28,2 +36,43 @@ return this.files.values();

exports.FileCollection = FileCollection;
function getItemFromText(relativePath, text, options = {}) {
const encoder = new TextEncoder();
const data = encoder.encode(text);
return {
relativePath,
name: relativePath.split('/').pop(),
lastModified: options.dateModified || Date.now(),
size: data.length,
text: async () => {
return text;
},
arrayBuffer: async () => {
return data.buffer;
},
stream: () => {
throw new Error('stream no implemented');
},
};
}
function getItemFromArrayBuffer(relativePath, arrayBuffer, options = {}) {
const decoder = new TextDecoder();
const text = decoder.decode(arrayBuffer);
return {
relativePath,
name: relativePath.split('/').pop(),
lastModified: options.dateModified || Date.now(),
size: arrayBuffer.byteLength,
text: async () => {
return text;
},
arrayBuffer: async () => {
return arrayBuffer;
},
stream: () => {
throw new Error('stream no implemented');
},
};
}
function getItemFromTypedArray(relativePath, typedArray, options = {}) {
return getItemFromArrayBuffer(relativePath, typedArray.buffer, options);
}
//# sourceMappingURL=FileCollection.js.map

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

if (node_stream_1.Readable.toWeb) {
//@ts-expect-error todo should be fixed
return node_stream_1.Readable.toWeb((0, node_fs_1.createReadStream)(current));

@@ -57,0 +58,0 @@ }

import JSZip from 'jszip';
import { FileCollection } from './FileCollection';
export declare type ZipFileContent = Parameters<typeof JSZip.loadAsync>[0];
import { FileCollectionItem } from './FileCollectionItem';
import { FilterOptions } from './utilities/maybeFilter';
export type ZipFileContent = Parameters<typeof JSZip.loadAsync>[0];
/**

@@ -9,3 +11,4 @@ * Create a FileCollection from a zip

*/
export declare function fileCollectionFromZip(zipContent: ZipFileContent): Promise<FileCollection>;
export declare function fileCollectionFromZip(zipContent: ZipFileContent, options?: FilterOptions): Promise<FileCollection>;
export declare function fileCollectionItemsFromZip(zipContent: ZipFileContent): Promise<FileCollectionItem[]>;
//# sourceMappingURL=fileCollectionFromZip.d.ts.map

@@ -6,5 +6,6 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.fileCollectionFromZip = void 0;
exports.fileCollectionItemsFromZip = exports.fileCollectionFromZip = void 0;
const jszip_1 = __importDefault(require("jszip"));
const FileCollection_1 = require("./FileCollection");
const maybeFilter_1 = require("./utilities/maybeFilter");
/**

@@ -15,6 +16,12 @@ * Create a FileCollection from a zip

*/
async function fileCollectionFromZip(zipContent) {
async function fileCollectionFromZip(zipContent, options = {}) {
let fileCollectionItems = await fileCollectionItemsFromZip(zipContent);
fileCollectionItems = await (0, maybeFilter_1.maybeFilter)(fileCollectionItems, options);
return new FileCollection_1.FileCollection(fileCollectionItems);
}
exports.fileCollectionFromZip = fileCollectionFromZip;
async function fileCollectionItemsFromZip(zipContent) {
const jsZip = new jszip_1.default();
const zip = await jsZip.loadAsync(zipContent);
const fileCollectionItems = [];
let fileCollectionItems = [];
for (let key in zip.files) {

@@ -50,5 +57,5 @@ const entry = zip.files[key];

}
return new FileCollection_1.FileCollection(fileCollectionItems);
return fileCollectionItems;
}
exports.fileCollectionFromZip = fileCollectionFromZip;
exports.fileCollectionItemsFromZip = fileCollectionItemsFromZip;
//# sourceMappingURL=fileCollectionFromZip.js.map

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

const cross_fetch_1 = __importDefault(require("cross-fetch"));
const FileCollection_1 = require("./FileCollection");
const fileCollectionFromZip_1 = require("./fileCollectionFromZip");

@@ -17,6 +18,6 @@ /**

const response = await (0, cross_fetch_1.default)(url);
const arrayBuffer = await response.arrayBuffer();
return (0, fileCollectionFromZip_1.fileCollectionFromZip)(arrayBuffer);
const filecollectionItem = await (0, fileCollectionFromZip_1.fileCollectionItemsFromZip)(await response.arrayBuffer());
return new FileCollection_1.FileCollection(filecollectionItem);
}
exports.fileCollectionFromZipURL = fileCollectionFromZipURL;
//# sourceMappingURL=fileCollectionFromZipURL.js.map
import { FileCollectionItem } from './FileCollectionItem';
import { FilterOptions } from './utilities/maybeFilter';
/**

@@ -17,3 +18,3 @@ * Some files in the fileCollectionItems may actually be gzip. This method will ungzip those files.

gzipExtensions?: string[];
}): Promise<FileCollectionItem[]>;
} & FilterOptions): Promise<FileCollectionItem[]>;
//# sourceMappingURL=fileCollectionItemsUngzip.d.ts.map

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

const ungzipStream_1 = require("./ungzipStream");
const maybeFilter_1 = require("./utilities/maybeFilter");
/**

@@ -44,2 +45,3 @@ * Some files in the fileCollectionItems may actually be gzip. This method will ungzip those files.

},
//@ts-expect-error todo should be fixed
stream: () => {

@@ -52,3 +54,3 @@ return (0, ungzipStream_1.ungzipStream)(file);

}
return fileCollectionItems.sort((a, b) => a.relativePath < b.relativePath ? -1 : 1);
return (0, maybeFilter_1.maybeFilter)(fileCollectionItems.sort((a, b) => a.relativePath < b.relativePath ? -1 : 1), options);
}

@@ -55,0 +57,0 @@ exports.fileCollectionItemsUngzip = fileCollectionItemsUngzip;

import { FileCollectionItem } from './FileCollectionItem';
import { FilterOptions } from './utilities/maybeFilter';
/**

@@ -17,3 +18,3 @@ * Some files in the fileCollectionItems may actually be zip. This method will unzip those files.

zipExtensions?: string[];
}): Promise<FileCollectionItem[]>;
} & FilterOptions): Promise<FileCollectionItem[]>;
//# sourceMappingURL=fileCollectionItemsUnzip.d.ts.map

@@ -26,4 +26,4 @@ "use strict";

}
const zipFileCollection = await (0, fileCollectionFromZip_1.fileCollectionFromZip)(await file.arrayBuffer());
for (let zipEntry of zipFileCollection) {
const zipFileCollectionItems = await (0, fileCollectionFromZip_1.fileCollectionItemsFromZip)(await file.arrayBuffer());
for (let zipEntry of zipFileCollectionItems) {
zipEntry.relativePath = `${file.relativePath}/${zipEntry.relativePath}`;

@@ -30,0 +30,0 @@ fileCollectionItems.push(zipEntry);

import { FileCollection } from './FileCollection';
import { FileCollectionItem } from './FileCollectionItem';
export declare type StringObject = Record<string, string>;
declare type GroupByOption = 'baseDir' | 'extension' | 'filename' | ((file?: FileCollectionItem, fileInfo?: ReturnType<typeof getFileInfo>) => string);
export type StringObject = Record<string, string>;
type GroupByOption = 'baseDir' | 'extension' | 'filename' | ((file?: FileCollectionItem, fileInfo?: ReturnType<typeof getFileInfo>) => string);
interface GroupOfFileCollection {

@@ -6,0 +6,0 @@ meta: StringObject;

export * from './fileCollectionFromPath';
export * from './fileCollectionFromPaths';
export * from './fileCollectionFromZip';
export { fileCollectionFromZip } from './fileCollectionFromZip';
export * from './fileCollectionFromZipURL';

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

@@ -17,5 +17,7 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.fileCollectionFromZip = void 0;
__exportStar(require("./fileCollectionFromPath"), exports);
__exportStar(require("./fileCollectionFromPaths"), exports);
__exportStar(require("./fileCollectionFromZip"), exports);
var fileCollectionFromZip_1 = require("./fileCollectionFromZip");
Object.defineProperty(exports, "fileCollectionFromZip", { enumerable: true, get: function () { return fileCollectionFromZip_1.fileCollectionFromZip; } });
__exportStar(require("./fileCollectionFromZipURL"), exports);

@@ -22,0 +24,0 @@ __exportStar(require("./fileCollectionFromWebservice"), exports);

import { ExpandOptions } from '../ExpandOptions';
import { FileCollectionItem } from '../FileCollectionItem';
import { FilterOptions } from './maybeFilter';
/**

@@ -9,3 +10,3 @@ * Utility function that allows to expand gzip and zip files without really expanding them

*/
export declare function maybeExpand(fileCollectionItems: FileCollectionItem[], options: ExpandOptions): Promise<FileCollectionItem[]>;
export declare function maybeExpand(fileCollectionItems: FileCollectionItem[], options: ExpandOptions & FilterOptions): Promise<FileCollectionItem[]>;
//# sourceMappingURL=maybeExpand.d.ts.map

@@ -13,5 +13,11 @@ "use strict";

async function maybeExpand(fileCollectionItems, options) {
const { unzip = {}, ungzip = {} } = options;
fileCollectionItems = await (0, fileCollectionItemsUnzip_1.fileCollectionItemsUnzip)(fileCollectionItems, unzip);
fileCollectionItems = await (0, fileCollectionItemsUngzip_1.fileCollectionItemsUngzip)(fileCollectionItems, ungzip);
const { unzip = {}, ungzip = {}, ...res } = options;
fileCollectionItems = await (0, fileCollectionItemsUnzip_1.fileCollectionItemsUnzip)(fileCollectionItems, {
...unzip,
...res,
});
fileCollectionItems = await (0, fileCollectionItemsUngzip_1.fileCollectionItemsUngzip)(fileCollectionItems, {
...ungzip,
...res,
});
return fileCollectionItems;

@@ -18,0 +24,0 @@ }

import { FileCollectionItem } from '../FileCollectionItem';
export declare type FilterOptions = {
export type FilterOptions = {
/**

@@ -4,0 +4,0 @@ * Should we ignored files starting with dot

{
"name": "filelist-utils",
"version": "1.5.1",
"version": "1.6.0-pre.1675462420",
"description": "Create a FileCollection from a path or a zip file",

@@ -48,15 +48,15 @@ "main": "./lib/index.js",

"devDependencies": {
"@babel/plugin-transform-modules-commonjs": "^7.18.6",
"@babel/plugin-transform-modules-commonjs": "^7.20.11",
"@babel/preset-typescript": "^7.18.6",
"@types/jest": "^29.1.2",
"@types/jest": "^29.4.0",
"@types/pako": "^2.0.0",
"cheminfo-build": "^1.1.11",
"eslint": "^8.25.0",
"eslint-config-cheminfo-typescript": "^11.1.0",
"jest": "^29.2.0",
"msw": "^0.47.4",
"prettier": "^2.7.1",
"rimraf": "^3.0.2",
"typescript": "^4.8.4",
"undici": "^5.11.0"
"cheminfo-build": "^1.2.0",
"eslint": "^8.33.0",
"eslint-config-cheminfo-typescript": "^11.2.2",
"jest": "^29.4.1",
"msw": "^1.0.0",
"prettier": "^2.8.3",
"rimraf": "^4.1.2",
"typescript": "^4.9.5",
"undici": "^5.16.0"
},

@@ -66,4 +66,4 @@ "dependencies": {

"jszip": "^3.10.1",
"pako": "^2.0.4"
"pako": "^2.1.0"
}
}
import { FileCollectionItem } from './FileCollectionItem';
import {
fileCollectionItemsZip,
FileCollectionItemsZipOptions,
} from './fileCollectionItemsZip';
import { fileCollectionToZip } from './fileCollectionToZip';

@@ -22,9 +19,32 @@ export class FileCollection {

* is the zipped file (called by default 'file.zip')
* Not sure this is super useful and we should probably remove it and replace it by fileCollectionToZip
*/
async zip(options: FileCollectionItemsZipOptions = {}) {
return new FileCollection([
await fileCollectionItemsZip(this.files, options),
]);
async zip() {
return fileCollectionToZip(this);
}
addText(
relativePath: string,
text: string,
options: { dateModified?: number } = {},
) {
this.files.push(getItemFromText(relativePath, text, options));
}
addArrayBuffer(
relativePath: string,
arrayBuffer: ArrayBuffer,
options: { dateModified?: number } = {},
) {
this.files.push(getItemFromArrayBuffer(relativePath, arrayBuffer, options));
}
addTypedArray(
relativePath: string,
typedArray: Uint8Array,
options: { dateModified?: number } = {},
) {
this.files.push(getItemFromTypedArray(relativePath, typedArray, options));
}
[Symbol.iterator]() {

@@ -34,1 +54,57 @@ return this.files.values();

}
function getItemFromText(
relativePath: string,
text: string,
options: { dateModified?: number } = {},
): FileCollectionItem {
const encoder = new TextEncoder();
const data = encoder.encode(text);
return {
relativePath,
name: relativePath.split('/').pop() as string,
lastModified: options.dateModified || Date.now(),
size: data.length,
text: async () => {
return text;
},
arrayBuffer: async () => {
return data.buffer;
},
stream: () => {
throw new Error('stream no implemented');
},
};
}
function getItemFromArrayBuffer(
relativePath: string,
arrayBuffer: ArrayBuffer,
options: { dateModified?: number } = {},
): FileCollectionItem {
const decoder = new TextDecoder();
const text = decoder.decode(arrayBuffer);
return {
relativePath,
name: relativePath.split('/').pop() as string,
lastModified: options.dateModified || Date.now(),
size: arrayBuffer.byteLength,
text: async () => {
return text;
},
arrayBuffer: async () => {
return arrayBuffer;
},
stream: () => {
throw new Error('stream no implemented');
},
};
}
function getItemFromTypedArray(
relativePath: string,
typedArray: Uint8Array,
options: { dateModified?: number } = {},
): FileCollectionItem {
return getItemFromArrayBuffer(relativePath, typedArray.buffer, options);
}

@@ -64,2 +64,3 @@ import { createReadStream } from 'node:fs';

if (Readable.toWeb) {
//@ts-expect-error todo should be fixed
return Readable.toWeb(createReadStream(current));

@@ -66,0 +67,0 @@ }

@@ -5,2 +5,3 @@ import JSZip from 'jszip';

import { FileCollectionItem } from './FileCollectionItem';
import { FilterOptions, maybeFilter } from './utilities/maybeFilter';

@@ -16,7 +17,13 @@ export type ZipFileContent = Parameters<typeof JSZip.loadAsync>[0];

zipContent: ZipFileContent,
options: FilterOptions = {},
): Promise<FileCollection> {
let fileCollectionItems = await fileCollectionItemsFromZip(zipContent);
fileCollectionItems = await maybeFilter(fileCollectionItems, options);
return new FileCollection(fileCollectionItems);
}
export async function fileCollectionItemsFromZip(zipContent: ZipFileContent) {
const jsZip = new JSZip();
const zip = await jsZip.loadAsync(zipContent);
const fileCollectionItems: FileCollectionItem[] = [];
let fileCollectionItems: FileCollectionItem[] = [];
for (let key in zip.files) {

@@ -51,3 +58,3 @@ const entry = zip.files[key];

}
return new FileCollection(fileCollectionItems);
return fileCollectionItems;
}
import fetch from 'cross-fetch';
import { FileCollection } from './FileCollection';
import { fileCollectionFromZip } from './fileCollectionFromZip';
import { fileCollectionItemsFromZip } from './fileCollectionFromZip';

@@ -15,5 +15,6 @@ /**

const response = await fetch(url);
const arrayBuffer = await response.arrayBuffer();
return fileCollectionFromZip(arrayBuffer);
const filecollectionItem = await fileCollectionItemsFromZip(
await response.arrayBuffer(),
);
return new FileCollection(filecollectionItem);
}

@@ -5,2 +5,3 @@ import { ungzip } from 'pako';

import { ungzipStream } from './ungzipStream';
import { FilterOptions, maybeFilter } from './utilities/maybeFilter';

@@ -25,3 +26,3 @@ /**

gzipExtensions?: string[];
} = {},
} & FilterOptions = {},
): Promise<FileCollectionItem[]> {

@@ -58,2 +59,3 @@ let { gzipExtensions = ['gz'] } = options;

},
//@ts-expect-error todo should be fixed
stream: () => {

@@ -68,4 +70,7 @@ return ungzipStream(file);

return fileCollectionItems.sort((a, b) =>
a.relativePath < b.relativePath ? -1 : 1,
return maybeFilter(
fileCollectionItems.sort((a, b) =>
a.relativePath < b.relativePath ? -1 : 1,
),
options,
);

@@ -72,0 +77,0 @@ }

import { FileCollectionItem } from './FileCollectionItem';
import { fileCollectionFromZip } from './fileCollectionFromZip';
import { fileCollectionItemsFromZip } from './fileCollectionFromZip';
import { FilterOptions } from './utilities/maybeFilter';

@@ -22,3 +23,3 @@ /**

zipExtensions?: string[];
} = {},
} & FilterOptions = {},
): Promise<FileCollectionItem[]> {

@@ -38,6 +39,7 @@ let { zipExtensions = ['zip'] } = options;

}
const zipFileCollection = await fileCollectionFromZip(
const zipFileCollectionItems = await fileCollectionItemsFromZip(
await file.arrayBuffer(),
);
for (let zipEntry of zipFileCollection) {
for (let zipEntry of zipFileCollectionItems) {
zipEntry.relativePath = `${file.relativePath}/${zipEntry.relativePath}`;

@@ -44,0 +46,0 @@ fileCollectionItems.push(zipEntry);

export * from './fileCollectionFromPath';
export * from './fileCollectionFromPaths';
export * from './fileCollectionFromZip';
export { fileCollectionFromZip } from './fileCollectionFromZip';
export * from './fileCollectionFromZipURL';

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

@@ -6,2 +6,4 @@ import { ExpandOptions } from '../ExpandOptions';

import { FilterOptions } from './maybeFilter';
/**

@@ -15,14 +17,14 @@ * Utility function that allows to expand gzip and zip files without really expanding them

fileCollectionItems: FileCollectionItem[],
options: ExpandOptions,
options: ExpandOptions & FilterOptions,
): Promise<FileCollectionItem[]> {
const { unzip = {}, ungzip = {} } = options;
fileCollectionItems = await fileCollectionItemsUnzip(
fileCollectionItems,
unzip,
);
fileCollectionItems = await fileCollectionItemsUngzip(
fileCollectionItems,
ungzip,
);
const { unzip = {}, ungzip = {}, ...res } = options;
fileCollectionItems = await fileCollectionItemsUnzip(fileCollectionItems, {
...unzip,
...res,
});
fileCollectionItems = await fileCollectionItemsUngzip(fileCollectionItems, {
...ungzip,
...res,
});
return fileCollectionItems;
}

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

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

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