filelist-utils
Advanced tools
Comparing version 1.6.0 to 1.7.0-pre.1676553431
import JSZip from 'jszip'; | ||
import { FileCollection } from './FileCollection'; | ||
import { FileCollectionItem } from './FileCollectionItem'; | ||
import { FilterOptions } from './utilities/maybeFilter'; | ||
export type ZipFileContent = Parameters<typeof JSZip.loadAsync>[0]; | ||
@@ -9,3 +11,4 @@ /** | ||
*/ | ||
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 |
@@ -1,2 +0,2 @@ | ||
export interface BaseFile { | ||
export interface FileCollectionItem { | ||
relativePath: string; | ||
@@ -6,4 +6,2 @@ name: string; | ||
size?: number; | ||
} | ||
export interface FileCollectionItem extends Required<BaseFile> { | ||
arrayBuffer(): Promise<ArrayBuffer>; | ||
@@ -10,0 +8,0 @@ stream(): ReadableStream<Uint8Array>; |
@@ -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); |
export * from './fileCollectionFromPath'; | ||
export * from './fileCollectionFromPaths'; | ||
export * from './fileCollectionFromZip'; | ||
export * from './fileCollectionFromZipURL'; | ||
export * from './fileCollectionFromWebservice'; | ||
export { fileCollectionFromZip } from './fileCollectionFromZip'; | ||
export * from './fileCollectionFromFileList'; | ||
export * from './fileCollectionFromFileArray'; | ||
export * from './fileCollectionFromFiles'; | ||
export * from './fileCollectionFromSource'; | ||
export * from './groupFiles'; | ||
@@ -10,0 +8,0 @@ export * from './FileCollection'; |
@@ -0,12 +1,15 @@ | ||
// creates a fileCollection from a local FS path | ||
export * from './fileCollectionFromPath'; | ||
export * from './fileCollectionFromPaths'; | ||
export * from './fileCollectionFromZip'; | ||
export * from './fileCollectionFromZipURL'; | ||
export * from './fileCollectionFromWebservice'; | ||
// creates a fileCollection from the zip content | ||
export { fileCollectionFromZip } from './fileCollectionFromZip'; | ||
// creates a fileCollection from a FileList that is obtained from a drag / drop in the browser | ||
export * from './fileCollectionFromFileList'; | ||
export * from './fileCollectionFromFileArray'; | ||
// you can also create a fileCollection from a list of files (native File objects from the browser) | ||
export * from './fileCollectionFromFiles'; | ||
export * from './fileCollectionFromSource'; | ||
export * from './groupFiles'; | ||
// typescript types | ||
export * from './FileCollection'; | ||
export * from './FileCollectionItem'; | ||
//# sourceMappingURL=index.js.map |
import JSZip from 'jszip'; | ||
import { FileCollection } from './FileCollection'; | ||
import { FileCollectionItem } from './FileCollectionItem'; | ||
import { FilterOptions } from './utilities/maybeFilter'; | ||
export type ZipFileContent = Parameters<typeof JSZip.loadAsync>[0]; | ||
@@ -9,3 +11,4 @@ /** | ||
*/ | ||
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 |
@@ -1,2 +0,2 @@ | ||
export interface BaseFile { | ||
export interface FileCollectionItem { | ||
relativePath: string; | ||
@@ -6,4 +6,2 @@ name: string; | ||
size?: number; | ||
} | ||
export interface FileCollectionItem extends Required<BaseFile> { | ||
arrayBuffer(): Promise<ArrayBuffer>; | ||
@@ -10,0 +8,0 @@ stream(): ReadableStream<Uint8Array>; |
@@ -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); |
export * from './fileCollectionFromPath'; | ||
export * from './fileCollectionFromPaths'; | ||
export * from './fileCollectionFromZip'; | ||
export * from './fileCollectionFromZipURL'; | ||
export * from './fileCollectionFromWebservice'; | ||
export { fileCollectionFromZip } from './fileCollectionFromZip'; | ||
export * from './fileCollectionFromFileList'; | ||
export * from './fileCollectionFromFileArray'; | ||
export * from './fileCollectionFromFiles'; | ||
export * from './fileCollectionFromSource'; | ||
export * from './groupFiles'; | ||
@@ -10,0 +8,0 @@ export * from './FileCollection'; |
@@ -17,13 +17,18 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.fileCollectionFromZip = void 0; | ||
// creates a fileCollection from a local FS path | ||
__exportStar(require("./fileCollectionFromPath"), exports); | ||
__exportStar(require("./fileCollectionFromPaths"), exports); | ||
__exportStar(require("./fileCollectionFromZip"), exports); | ||
__exportStar(require("./fileCollectionFromZipURL"), exports); | ||
__exportStar(require("./fileCollectionFromWebservice"), exports); | ||
// creates a fileCollection from the zip content | ||
var fileCollectionFromZip_1 = require("./fileCollectionFromZip"); | ||
Object.defineProperty(exports, "fileCollectionFromZip", { enumerable: true, get: function () { return fileCollectionFromZip_1.fileCollectionFromZip; } }); | ||
// creates a fileCollection from a FileList that is obtained from a drag / drop in the browser | ||
__exportStar(require("./fileCollectionFromFileList"), exports); | ||
__exportStar(require("./fileCollectionFromFileArray"), exports); | ||
// you can also create a fileCollection from a list of files (native File objects from the browser) | ||
__exportStar(require("./fileCollectionFromFiles"), exports); | ||
__exportStar(require("./fileCollectionFromSource"), exports); | ||
__exportStar(require("./groupFiles"), exports); | ||
// typescript types | ||
__exportStar(require("./FileCollection"), exports); | ||
__exportStar(require("./FileCollectionItem"), exports); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "filelist-utils", | ||
"version": "1.6.0", | ||
"version": "1.7.0-pre.1676553431", | ||
"description": "Create a FileCollection from a path or a zip file", | ||
@@ -53,10 +53,10 @@ "main": "./lib/index.js", | ||
"cheminfo-build": "^1.2.0", | ||
"eslint": "^8.33.0", | ||
"eslint": "^8.34.0", | ||
"eslint-config-cheminfo-typescript": "^11.2.2", | ||
"jest": "^29.4.1", | ||
"msw": "^1.0.0", | ||
"prettier": "^2.8.3", | ||
"jest": "^29.4.3", | ||
"msw": "^1.0.1", | ||
"prettier": "^2.8.4", | ||
"rimraf": "^4.1.2", | ||
"typescript": "^4.9.5", | ||
"undici": "^5.16.0" | ||
"undici": "^5.19.1" | ||
}, | ||
@@ -63,0 +63,0 @@ "dependencies": { |
@@ -30,2 +30,27 @@ # filelist-utils | ||
## Load and Save from remote server | ||
// You should have a webservice that returns this kind of object | ||
```js | ||
const source = { | ||
files: [ | ||
{ | ||
name: 'data.zip', | ||
size: 1589, | ||
relativePath: 'dataUnzip/data.zip', | ||
lastModified: 1664430693588, | ||
}, | ||
{ | ||
name: 'a.txt', | ||
size: 1, | ||
relativePath: 'dataUnzip/dir1/a.txt', | ||
lastModified: 1664430693588, | ||
}, | ||
], | ||
baseURL: 'http://localhost/', | ||
}; | ||
const fileCollection = fileCollectionFromSource(source); | ||
``` | ||
## Installation | ||
@@ -32,0 +57,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; | ||
} |
@@ -1,2 +0,2 @@ | ||
export interface BaseFile { | ||
export interface FileCollectionItem { | ||
relativePath: string; | ||
@@ -6,5 +6,2 @@ name: string; | ||
size?: number; | ||
} | ||
export interface FileCollectionItem extends Required<BaseFile> { | ||
arrayBuffer(): Promise<ArrayBuffer>; | ||
@@ -11,0 +8,0 @@ stream(): ReadableStream<Uint8Array>; |
import { FileCollectionItem } from './FileCollectionItem'; | ||
import { fileCollectionFromZip } from './fileCollectionFromZip'; | ||
import { fileCollectionItemsFromZip } from './fileCollectionFromZip'; | ||
@@ -37,6 +37,7 @@ /** | ||
} | ||
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}`; | ||
@@ -43,0 +44,0 @@ fileCollectionItems.push(zipEntry); |
@@ -0,11 +1,19 @@ | ||
// creates a fileCollection from a local FS path | ||
export * from './fileCollectionFromPath'; | ||
export * from './fileCollectionFromPaths'; | ||
export * from './fileCollectionFromZip'; | ||
export * from './fileCollectionFromZipURL'; | ||
export * from './fileCollectionFromWebservice'; | ||
// creates a fileCollection from the zip content | ||
export { fileCollectionFromZip } from './fileCollectionFromZip'; | ||
// creates a fileCollection from a FileList that is obtained from a drag / drop in the browser | ||
export * from './fileCollectionFromFileList'; | ||
export * from './fileCollectionFromFileArray'; | ||
// you can also create a fileCollection from a list of files (native File objects from the browser) | ||
export * from './fileCollectionFromFiles'; | ||
export * from './fileCollectionFromSource'; | ||
export * from './groupFiles'; | ||
// typescript types | ||
export * from './FileCollection'; | ||
export * from './FileCollectionItem'; |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
86
2
157511
201
2458
1