Installations
npm install fs-updater
Score
84.3
Supply Chain
97.5
Quality
72.8
Maintenance
100
Vulnerability
98.6
License
Releases
Unable to fetch releases
Developer
broccolijs
Developer Guide
Module System
CommonJS
Min. Node Version
>=6.0.0
Typescript Support
No
Node Version
9.5.0
NPM Version
5.6.0
Statistics
1 Stars
15 Commits
9 Forks
5 Watching
6 Branches
3 Contributors
Updated on 23 Feb 2018
Languages
JavaScript (100%)
Total Downloads
Cumulative downloads
Total Downloads
39,369,625
Last day
-31.1%
18,496
Compared to previous day
Last week
-13.4%
112,086
Compared to previous week
Last month
16.9%
536,950
Compared to previous month
Last year
21.2%
7,766,859
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dev Dependencies
4
node-fs-updater
Repeatedly write an in-memory directory tree to disk, with incremental updating.
Installation
This package requires Node version 6.0.0 or newer.
1npm install --save fs-updater
Usage
1let FSUpdater = require("fs-updater"); 2let { File, Directory, DirectoryIndex } = FSUpdater; 3 4// output_dir must either be an empty directory or not exist at all 5let fsUpdater = new FSUpdater('./output_dir')
Let's create the following directory structure, where ->
indicates a symlink
(or a copy on Windows):
output_dir
├── file -> /path/to/some/file
├── dir1/ -> /path/to/some/dir
└── dir2/
└── another_file -> /path/to/another/file
1let dir = new DirectoryIndex([ 2 ['file', new File('/path/to/some/file')], 3 ['dir1', new Directory('/path/to/some/dir')], 4 ['dir2', new DirectoryIndex([ 5 ['another_file', new File('/path/to/another/file')] 6 ])] 7]); 8 9// Write it to ./output_dir 10fsUpdater.update(dir);
Now let's create an updated similar directory structure:
.
├── file -> /path/to/some/file
└── dir1/ -> /path/to/some/dir
1dir = new DirectoryIndex([ 2 ['file', new File('/path/to/some/file')], 3 ['dir1', new Directory('/path/to/some/dir')] 4]); 5 6// Now update output_dir incrementally 7fsUpdater.update(dir);
Object re-use
It is recommended that you rebuild all your File
, Directory
and
DirectoryIndex
objects from scratch each time you call fsUpdater.update
. If
you re-use objects, the following rules apply:
First, do not mutate the objects that you pass into FSUpdater
, or their
sub-objects. That is, after calling fsUpdater.update(dir)
, you must no longer
call dir.set(...)
.
Second, you may re-use unchanged File
, Directory
and DirectoryIndex
objects only if you know that the file contents they point to recursively
have not changed. This is typically only the case if they point into directories
that you control, and if those directories in turn contain no symlinks to
outside directories under the user's control.
For example, this is always OK:
1let file = new String('/the/file');
2fsUpdater.update(new DirectoryIndex([
3 ['file', file]
4]);
5
6// Create new File object with identical path
7file = new String('/the/file');
8fsUpdater.update(new DirectoryIndex([
9 ['file', file]
10]);
But this is only OK if the contents of /the/file
have not changed between
calls to .update
:
1let file = new String('/the/file');
2fsUpdater.update(new DirectoryIndex([
3 ['file', file]
4]);
5
6// Re-use the File object
7fsUpdater.update(new DirectoryIndex([
8 ['file', file]
9]);
Reference
-
FSUpdater
: An object used to repeatedly update an output directory.-
new FSUpdater(outputPath, options)
: Create a newFSUpdater
object. TheoutputPath
must be an empty directory or absent.It is important that the
FSUpdater
has exclusive access to theoutputPath
directory.FSUpdater.prototype.update
calls rimraf, which can be dangerous in the presence of symlinks if unexpected changes have been made to theoutputPath
directory.options.canSymlink
(boolean): If true, use symlinks; if false, copy files and use junctions. Ifnull
(default), auto-detect. -
FSUpdater.prototype.update(directory)
: Update theoutputPath
directory to mirror the contents of thedirectory
object, which is either aDirectoryIndex
(an in-memory directory) or aDirectory
(a directory on disk).Important note: You may re-use
File
objects contained in theDirectoryIndex
between repeated calls to.update()
only if the file contents have not changed. Similarly, you may re-useDirectoryIndex
andDirectory
objects only if no changes have been made to the directory or any files or subdirectories recursively, including those reachable through symlinks.
-
-
FSUpdater.DirectoryIndex
: A subclass of Map representing an in-memory directory; see the documentation there.DirectoryIndex
objects map file names (string
primitives, without paths) toDirectoryIndex
,Directory
orFile
objects. -
FSUpdater.Directory
: A directory on disk. Think of this as an in-memory symlink to a directory.-
new Directory(path)
: Create a newDirectory
object pointing to the directory atpath
. -
Directory.prototype.valueOf()
: Return thepath
. -
Directory.prototype.getIndexSync()
: Read the physical directory and return aDirectoryIndex
. TheDirectoryIndex
object is cached between repeated calls togetIndexSync()
.
-
-
FSUpdater.File
: Represents a file on disk. Think of this as an in-memory symlink.-
new File(path)
: Create a newFile
object pointing to the file atpath
. -
File.prototype.valueOf()
: Return thepath
.
-
-
FSUpdater.makeFSObject(path)
: Return aFile
orDirectory
object, depending on the file type on disk. This function follows symlinks.
Contributing
Clone this repo and run the tests like so:
npm install
npm test
Issues and pull requests are welcome. If you change code, be sure to re-run
npm test
. Oftentimes it's useful to add or update tests as well.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
Found 0/15 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
17 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-v88g-cgmw-v5xw
- Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-h6ch-v84p-w6p9
- Warn: Project is vulnerable to: GHSA-4q6p-r6v2-jvc5
- Warn: Project is vulnerable to: GHSA-2pr6-76vf-7546
- Warn: Project is vulnerable to: GHSA-8j8c-7jfh-h6hx
- Warn: Project is vulnerable to: GHSA-4xc9-xhrj-v574
- Warn: Project is vulnerable to: GHSA-x5rq-j2xg-h7qm
- Warn: Project is vulnerable to: GHSA-jf85-cpcp-j695
- Warn: Project is vulnerable to: GHSA-p6mc-m468-83gw
- Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9
- Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-vh95-rmgr-6w4m / GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-g6ww-v8xp-vmwg
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
Score
1.7
/10
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to fs-updater
@pnpm/meta-updater
Keeps meta files up-to-date in a monorepo
fs-extra
fs-extra contains methods that aren't included in the vanilla Node.js fs package. Such as recursive mkdir, copy, and remove.
electron-updater
Cross platform updater for electron applications
graceful-fs
A drop-in replacement for fs, making various improvements.