files-from-path
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

files-from-path

Expand paths to file-like objects with name, readable stream and size.

Build JavaScript Style Guide Downloads

Install

npm install files-from-path

Usage

import { filesFromPaths } from 'files-from-path'

// Given a file system like:
// path/to/file.txt
// path/to/dir/a.pdf
// path/to/dir/images/cat.gif

const files = await filesFromPaths(['path/to/file.txt', 'path/to/dir'])
console.log(files)

// Output:
// [
//   { name: 'file.txt', stream: [Function: stream] },
//   { name: 'dir/b.pdf', stream: [Function: stream] },
//   { name: 'dir/images/cat.gif', stream: [Function: stream] },
// ]
// Note: common sub-path ("path/to/") is removed.

API

filesFromPaths

The following parameters can be provided to filesFromPaths:

Name Type Description
paths Iterable<string> File system path(s) to read from
[options] object options
[options.hidden] boolean Include .dot files in matched paths (default: false)
[options.sort] boolean Sort files by path (default: true)

It returns an array of file-like objects in the form:

{
  name: string
  stream: () => ReadableStream<Uint8Array>
  size: number
}

Releasing

Releasing to npm is done via release-please. A Release PR will be opened with a CHANGELOG update in after a PR is merged to main. Merging the release PR will publish the new version to npm.

Contributing

Feel free to join in. All welcome. Please open an issue!

License

Dual-licensed under Apache 2.0 OR MIT

Readme

Keywords

none

Package Sidebar

Install

npm i files-from-path

Weekly Downloads

10,633

Version

1.0.4

License

Apache-2.0 OR MIT

Unpacked Size

32.3 kB

Total Files

20

Last publish

Collaborators

  • alanshaw
  • vascosantos
  • it-dag-house