Codebase list node-read-file / a3d76a8
adds verb, updates docs jonschlinkert 8 years ago
2 changed file(s) with 123 addition(s) and 47 deletion(s). Raw diff Collapse all Expand all
0 # {%= name %} {%= badge("fury") %}
1
2 > {%= description %}
3
4 {%= include("install-npm", {save: true}) %}
5
6 ## Usage
7
8 ```js
9 var read = require('{%= name %}');
10
11 // async
12 read('foo.txt', function(err, buffer) {
13 //=> <Buffer 74 68 69 73 20 69 73 20 66 6f 6f>
14 });
15
16 // sync
17 var buffer = read.sync('foo.txt');
18 //=> <Buffer 74 68 69 73 20 69 73 20 66 6f 6f>
19 ```
20
21 ### BOM
22
23 if `utf8` encoding is used, byte order marks will be stripped
24
25 **async**
26
27 ```js
28 read('foo.txt', 'utf8', function(err, buffer) {
29 //=> 'some contents...'
30 });
31
32 // or
33 read('foo.txt', {encoding: 'utf8'} function(err, buffer) {
34 //=> 'some contents...'
35 });
36 ```
37
38 **sync**
39
40 ```js
41 read.sync('foo.txt', 'utf8');
42 // or
43 read('foo.txt', {encoding: 'utf8'});
44 ```
45
46 ### options.normalize
47
48 Pass `{ normalize: true }` on the options to strip windows carriage returns. This will also return a `utf8` string.
49
50
51 ## Related projects
52 {%= related(verb.related.list) %}
53
54 ## Running tests
55 {%= include("tests") %}
56
57 ## Contributing
58 {%= include("contributing") %}
59
60 ## Author
61 {%= include("author") %}
62
63 ## License
64 {%= copyright() %}
65 {%= license() %}
66
67 ***
68
69 {%= include("footer") %}
0 # read-file [![NPM version](https://badge.fury.io/js/read-file.png)](http://badge.fury.io/js/read-file)
0 # read-file [![NPM version](https://badge.fury.io/js/read-file.svg)](http://badge.fury.io/js/read-file)
11
2 > Lightweight methods for reading from the file system, async and sync, with extras for stripping byte order marks and normalizing newlines.
2 > Thin wrapper around fs.readFile and fs.readFileSync that also strips byte order marks when `utf8` encoding is chosen. Also optionally replaces windows newlines with unix newlines.
33
4 ## Install
5 Install with [npm](npmjs.org):
4 Install with [npm](https://www.npmjs.com/)
65
7 ```bash
8 npm i read-file --save-dev
6 ```sh
7 $ npm i read-file --save
98 ```
109
11
12 ## api
13 #### readFile
14
15 Read files asynchronously.
10 ## Usage
1611
1712 ```js
18 var file = require('read-file');
19 file.readFileSync('foo.txt');
13 var read = require('read-file');
14
15 // async
16 read('foo.txt', function(err, buffer) {
17 //=> <Buffer 74 68 69 73 20 69 73 20 66 6f 6f>
18 });
19
20 // sync
21 var buffer = read.sync('foo.txt');
22 //=> <Buffer 74 68 69 73 20 69 73 20 66 6f 6f>
2023 ```
2124
22 #### readFileSync
25 ### BOM
2326
24 Read files synchronously.
27 if `utf8` encoding is used, byte order marks will be stripped
28
29 **async**
2530
2631 ```js
27 var file = require('read-file');
28 file.readFile('foo.txt', callback);
32 read('foo.txt', 'utf8', function(err, buffer) {
33 //=> 'some contents...'
34 });
35
36 // or
37 read('foo.txt', {encoding: 'utf8'} function(err, buffer) {
38 //=> 'some contents...'
39 });
2940 ```
3041
31 #### encoding
32
33 Default encoding is `utf8`, this can be changed by passing an encoding as a second param:
42 **sync**
3443
3544 ```js
36 var file = require('read-file');
37 file.readFileSync('foo.txt', 'utf8');
45 read.sync('foo.txt', 'utf8');
3846 // or
39 file.readFile('foo.txt', 'utf8', callback);
47 read('foo.txt', {encoding: 'utf8'});
4048 ```
4149
42 #### normalizeNL
50 ### options.normalize
4351
44 Normalize all line endings to newlines, `\n`.
52 Pass `{ normalize: true }` on the options to strip windows carriage returns. This will also return a `utf8` string.
4553
46 ```js
47 var file = require('read-file');
48 var str = file.readFileSync('foo.txt');
49 file.normalizeNL(str);
54 ## Related projects
55
56 * [copy](https://github.com/jonschlinkert/copy): Copy files or directories using globs.
57 * [read-yaml](https://github.com/jonschlinkert/read-yaml): Very thin wrapper around js-yaml for directly reading in YAML files.
58 * [read-data](https://github.com/jonschlinkert/read-data): Read JSON or YAML files.
59 * [write](https://github.com/jonschlinkert/write): Write files to disk, creating intermediate directories if they don't exist.
60
61 ## Running tests
62
63 Install dev dependencies:
64
65 ```sh
66 $ npm i -d && npm test
5067 ```
5168
52 #### stripBOM
69 ## Contributing
5370
54 Strip byte order marks.
71 Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/read-file/issues/new)
5572
56 ```js
57 var file = require('read-file');
58 var str = file.readFileSync('foo.txt');
59 file.stripBOM(str);
60 ```
61
62
63 ## Authors
73 ## Author
6474
6575 **Jon Schlinkert**
6676
6777 + [github/jonschlinkert](https://github.com/jonschlinkert)
6878 + [twitter/jonschlinkert](http://twitter.com/jonschlinkert)
6979
70 **Brian Woodward**
80 ## License
7181
72 + [github/doowb](https://github.com/doowb)
73 + [twitter/doowb](http://twitter.com/jonschlinkert)
74
75 ## License
76 Copyright (c) 2014 Jon Schlinkert, contributors.
77 Released under the MIT license
82 Copyright © 2015 Jon Schlinkert
83 Released under the MIT license.
7884
7985 ***
8086
81 _This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on April 09, 2014._
87 _This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on July 17, 2015._