1.11.0 • Published 4 months ago

filelist-utils v1.11.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

filelist-utils

NPM version build status Test coverage npm download

Create a FileCollection from various sources.

Introduction

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:

  • a FileList (that implements an Iterator of File).
  • a relative path (with its basedir)
  • a webservice that returns a JSON containing an array of object that has the following properties: relativePath, name, lastModified, size

A FileCollection has an iterator on FileCollectionItem that has the following properties:

  • lastModified: number;
  • name: string;
  • relativePath: string;
  • size: number;
  • arrayBuffer(): Promise;
  • stream(): ReadableStream;
  • text(): Promise;

Load and Save from remote server

// 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);

Installation

npm i filelist-utils

Usage

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);

License

MIT

1.11.0

4 months ago

1.10.2

9 months ago

1.10.1

9 months ago

1.10.0

11 months ago

1.9.0

12 months ago

1.8.1

1 year ago

1.8.0

1 year ago

1.7.1

1 year ago

1.7.0

1 year ago

1.6.0

1 year ago

1.5.1

1 year ago

1.2.0

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

1.5.0

1 year ago

1.4.1

1 year ago

1.4.0

1 year ago

1.3.0

1 year ago

0.12.0

2 years ago

0.10.0

2 years ago

0.11.0

2 years ago

0.9.0

2 years ago

0.8.0

2 years ago

0.7.1

2 years ago

0.9.1

2 years ago

0.7.0

2 years ago

0.6.0

2 years ago

0.5.0

2 years ago

0.4.0

2 years ago