Create a FileCollection from various sources.
In order to make compatible code between the browser and node and to allow drag and drop of a folder it is useful to an abstraction level.
This package allows to create a FileCollection
from various sources:
relativePath
, name
, lastModified
, size
A FileCollection
has an iterator on FileCollectionItem
that has the following properties:
// You should have a webservice that returns this kind of object
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);
npm i filelist-utils
import { fileCollectionFromPath } from 'filelist-utils';
const fileCollection = fileCollectionFromPath(__dirname);
import { fileCollectionFromZip } from 'filelist-utils';
const zip = readFileSync(join(__dirname, 'test.zip'));
const fileCollection = fileCollectionFromZip(zip);