Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

feat: add from fs #1777

Merged
merged 9 commits into from
Dec 18, 2018
Merged

feat: add from fs #1777

merged 9 commits into from
Dec 18, 2018

Conversation

alanshaw
Copy link
Member

@alanshaw alanshaw commented Dec 12, 2018

This PR adds a new method addFromFs allowing users to more easily add files from their file system without having to specify every single file to add.

In the browser the user will receive a "not available" error.

I've pulled out a module glob-source.js - call it with some file paths and it returns a pull stream source that can be piped to ipfs.addPullStream.

This PR comes with the following added benefits:

  • ipfs add on the CLI uses glob-source.js - nice and DRY
  • glob-source.js uses the events that the glob module provides allowing the globbing to be a pull-pushable, which means that matched paths can begin to be added before all the globbing is done - faster
  • ipfs add now supports adding multiple paths, fixes Cannot add multiple files from command line #1625 - better
  • ipfs add --progress=false doesn't calculate the total size of the files to be added anymore! It didn't need to do that as the total was completely discarded when progress was disabled. It means we can add BIGGER directories without running into memory issues - stronger

const Path = require('path')
const isString = require('lodash/isString')
const pull = require('pull-stream')
const glob = require('glob')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't we just use https://www.npmjs.com/package/fast-glob ? it's faster and supports streams so we can go directly to pull-stream

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried it, and it's not significantly faster than glob, in fact in most tests it's slower (left is glob, right is fast-glob).

screenshot 2018-12-13 at 15 49 43

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

even using streams instead of glob events ? seems weird but if its faster like this im good with it

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know weird, maybe it is the stream to pull stream conversion? Anyway even weirder is that the benchmarks for fast-glob do not run against glob 😱 They benchmark globby, bash-glob, tiny-glob and glob-stream...but not regular glob 🙄.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol that kinda wtf and globby is based on fast-glob with some sindre sugar on top
anyway this looks fine and if your benchs show better numbers lets merge it

src/core/runtime/add-from-fs-nodejs.js Outdated Show resolved Hide resolved
src/utils/files/glob-source.js Outdated Show resolved Hide resolved
Alan Shaw added 7 commits December 17, 2018 10:30
License: MIT
Signed-off-by: Alan Shaw <[email protected]>
This PR adds a new method [`addFromFs`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#addfromfs) allowing users to more easily add files from their file system without having to specify every single file to add.

In the browser the user will receive a "not available" error.

I've pulled out a module `glob-source.js` - call it with some file paths and it returns a pull stream source that can be piped to `ipfs.addPullStream`.

This PR comes with the following added benefits:

* `ipfs add` on the CLI uses `glob-source.js` - **nice and DRY**
* `glob-source.js` uses the events that the `glob` module provides allowing the globbing to be a `pull-pushable`, which means that matched paths can begin to be added before all the globbing is done - **faster**
* `ipfs add` now supports adding multiple paths, fixes #1625 - **better**
* `ipfs add --progress=false` doesn't calculate the total size of the files to be added anymore! It didn't need to do that as the total was completely discarded when progress was disabled. It means we can add BIGGER directories without running into memory issues - **stronger**

License: MIT
Signed-off-by: Alan Shaw <[email protected]>
License: MIT
Signed-off-by: Alan Shaw <[email protected]>
License: MIT
Signed-off-by: Alan Shaw <[email protected]>
License: MIT
Signed-off-by: Alan Shaw <[email protected]>
License: MIT
Signed-off-by: Alan Shaw <[email protected]>
Alan Shaw added 2 commits December 17, 2018 12:33
License: MIT
Signed-off-by: Alan Shaw <[email protected]>
@alanshaw
Copy link
Member Author

@hugomrdias is this gtg now?

@alanshaw alanshaw merged commit 7315aa1 into master Dec 18, 2018
@alanshaw alanshaw deleted the feat/add-from-fs branch December 18, 2018 13:00
@ghost ghost removed the status/in-progress In progress label Dec 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot add multiple files from command line
3 participants