1 | # fs-sync
|
2 |
|
3 | > Synchronous fs with more fun
|
4 |
|
5 | ## Getting Started
|
6 | This module is created for the favor of use of `fs.xxxSync`.
|
7 |
|
8 | Once `fs-sync` is installed, you can use:
|
9 |
|
10 | var fs = require('fs-sync');
|
11 |
|
12 | if(fs.exists('package.json')){
|
13 | var pkg = fs.readJSON('package.json');
|
14 | }
|
15 |
|
16 | // You can also use methods of the built-in `fs`
|
17 |
|
18 | fs.readFileSync(...);
|
19 |
|
20 |
|
21 | ## Methods
|
22 |
|
23 | var fs = require('fs-sync');
|
24 |
|
25 | ### fs.defaultEncoding
|
26 | Type: `String`
|
27 |
|
28 | Default value: `'utf-8'`
|
29 |
|
30 | Global default encoding
|
31 |
|
32 | fs.defaultEncoding = 'utf-8'
|
33 |
|
34 | ### fs.copy()
|
35 |
|
36 | Copy a file or a whole directory to the destination. During this, necessary directories will be created.
|
37 |
|
38 | #### Syntax
|
39 |
|
40 | fs.copy(file, destpath, options);
|
41 | fs.copy(dir, destpath, options);
|
42 |
|
43 | #### file
|
44 | Type: `String`
|
45 |
|
46 | Path of file to be copied
|
47 |
|
48 | #### dir
|
49 | Type: `String`
|
50 |
|
51 | Path of directory to be copied
|
52 |
|
53 | #### options.force
|
54 | Type: `Boolean`
|
55 |
|
56 | Default value: `false`
|
57 |
|
58 | By default, `fs.copy` will not override existed files, set `options.force` as `true` to override.
|
59 |
|
60 |
|
61 | ### fs.mkdir()
|
62 | Commandline `mkdir` or `mkdir -p`
|
63 |
|
64 |
|
65 | ### fs.expand(patterns, options)
|
66 |
|
67 | Like `grunt.file.expand`, but the sequence of the arguments is different
|
68 |
|
69 |
|
70 | ### fs.write(file, content, options)
|
71 |
|
72 | #### options
|
73 | Type: `Object`
|
74 |
|
75 | The same as the `options` argument of [fs.writeFile](http://nodejs.org/api/fs.html#fs_fs_writefile_filename_data_options_callback)
|
76 |
|
77 | ### fs.read(file, options)
|
78 | Read a file
|
79 |
|
80 | #### options
|
81 | Type: `Object`
|
82 |
|
83 | The same as the `options` argument of [fs.writeFile](http://nodejs.org/api/fs.html#fs_fs_readfile_filename_options_callback), except:
|
84 |
|
85 | #### options.encoding
|
86 | Type: `String`
|
87 |
|
88 | Default value: `fs.defaultEncoding`
|
89 |
|
90 | ### fs.readJSON(file, options)
|
91 | Read a file as the JSON format, if the file content fails to be parsed as JSON, an error will be thrown.
|
92 |
|
93 | ### fs.delete()
|
94 |
|
95 | Delete a file or a whole directory. It's a dangerous action, be careful.
|
96 |
|
97 | #### Syntax
|
98 |
|
99 | fs.delete(file)
|
100 | fs.delete(dir)
|
101 |
|
102 |
|
103 | ### fs.exists()
|
104 |
|
105 | `arguments` will be called with `path.join`
|
106 |
|
107 | ### fs.isDir()
|
108 |
|
109 | ### fs.isFile()
|
110 |
|
111 | ### fs.isLink()
|
112 |
|
113 |
|
114 |
|
115 |
|