Set the `contents` property on a file object. Abstraction from vinyl-fs to support stream or non-stream usage.
Installations
npm install file-contents
Releases
Unable to fetch releases
Developer
jonschlinkert
Developer Guide
Module System
CommonJS
Min. Node Version
>=0.10.0
Typescript Support
No
Node Version
6.9.2
NPM Version
3.10.9
Statistics
8 Stars
39 Commits
3 Watching
2 Branches
2 Contributors
Updated on 14 Sept 2022
Languages
JavaScript (100%)
Total Downloads
Cumulative downloads
Total Downloads
34,220,516
Last day
-10.4%
15,561
Compared to previous day
Last week
-3.2%
84,012
Compared to previous week
Last month
-1.4%
362,617
Compared to previous month
Last year
0.8%
5,538,593
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
file-contents
Set the
contents
property on a file object. Abstraction from vinyl-fs to support stream or non-stream usage.
Install
Install with npm:
1$ npm install --save file-contents
This is inspired by the code in vinyl-fs src
. I needed a function that essentially did the same thing but could be used with stream or non-stream code.
Usage
1var through = require('through2'); 2var contents = require('file-contents'); 3 4function toStream(fp) { 5 var stream = through.obj(); 6 stream.write({path: fp}); 7 stream.end(); 8 return stream; 9} 10 11toStream('README.md') 12 .pipe(contents()) 13 .on('data', function(file) { 14 console.log(file.contents.toString()); 15 }); 16
async
An .async()
method is exposed for non-stream, async usage.
1contents.async({path: 'README.md'}, function (err, file) { 2 // results in something like: 3 // 4 // { path: 'README.md', 5 // stat: 6 // { dev: 16777218, 7 // mode: 33188, 8 // nlink: 1, 9 // uid: 501, 10 // gid: 20, 11 // rdev: 0, 12 // blksize: 4096, 13 // ino: 26436116, 14 // size: 2443, 15 // blocks: 8, 16 // atime: Fri Jul 17 2015 03:01:54 GMT-0400 (EDT), 17 // mtime: Wed Jul 15 2015 02:46:55 GMT-0400 (EDT), 18 // ctime: Wed Jul 15 2015 02:46:55 GMT-0400 (EDT), 19 // birthtime: Tue Jul 14 2015 23:03:58 GMT-0400 (EDT) }, 20 // contents: <Buffer 23 20 66 69 6c 65 2d 63 6f 6e 74 65 6e 74 73 20 5b 21 5b 4e 50 4d 20 76 65 72 73 69 6f 6e 5d 28 68 74 74 70 73 3a 2f 2f 62 61 64 67 65 2e 66 75 72 79 ... > } 21});
sync
A .sync()
method is exposed for non-stream, sync usage.
1var file = {path: 'README.md'}; 2contents.sync(file); 3// results in something like: 4// 5// { path: 'README.md', 6// stat: 7// { dev: 16777218, 8// mode: 33188, 9// nlink: 1, 10// uid: 501, 11// gid: 20, 12// rdev: 0, 13// blksize: 4096, 14// ino: 26436116, 15// size: 2443, 16// blocks: 8, 17// atime: Fri Jul 17 2015 03:01:54 GMT-0400 (EDT), 18// mtime: Wed Jul 15 2015 02:46:55 GMT-0400 (EDT), 19// ctime: Wed Jul 15 2015 02:46:55 GMT-0400 (EDT), 20// birthtime: Tue Jul 14 2015 23:03:58 GMT-0400 (EDT) }, 21// contents: <Buffer 23 20 66 69 6c 65 2d 63 6f 6e 74 65 6e 74 73 20 5b 21 5b 4e 50 4d 20 76 65 72 73 69 6f 6e 5d 28 68 74 74 70 73 3a 2f 2f 62 61 64 67 65 2e 66 75 72 79 ... > }
History
v0.2.0
- renames
.getContents
method to.async
- adds
.sync
method
About
Related projects
- file-stat: Set the
stat
property on a file object. Abstraction from vinyl-fs to support stream or… more | homepage - file-symlinks: Resolve symlinks and expose the
stat
property on a file object. | homepage - stream-loader: create a read stream from a glob of files. can be used as a loader-cache… more | homepage
- vinyl-fs: Vinyl adapter for the file system | homepage
- vinyl: Virtual file format. | homepage
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Building docs
(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)
To generate the readme, run the following command:
1$ npm install -g verbose/verb#dev verb-generate-readme && verb
Running tests
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
1$ npm install && npm test
Author
Jon Schlinkert
License
Copyright © 2017, Jon Schlinkert. MIT
This file was generated by verb-generate-readme, v0.4.2, on February 03, 2017.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
Reason
no effort to earn an OpenSSF best practices badge detected
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
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
Score
3
/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 More