UNPKG

2.03 kBMarkdownView Raw
1# fs-sync
2
3> Synchronous fs with more fun
4
5## Getting Started
6This module is created for the favor of use of `fs.xxxSync`.
7
8Once `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
26Type: `String`
27
28Default value: `'utf-8'`
29
30Global default encoding
31
32 fs.defaultEncoding = 'utf-8'
33
34### fs.copy()
35
36Copy 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
44Type: `String`
45
46Path of file to be copied
47
48#### dir
49Type: `String`
50
51Path of directory to be copied
52
53#### options.force
54Type: `Boolean`
55
56Default value: `false`
57
58By default, `fs.copy` will not override existed files, set `options.force` as `true` to override.
59
60
61### fs.mkdir()
62Commandline `mkdir` or `mkdir -p`
63
64
65### fs.expand(patterns, options)
66
67Like `grunt.file.expand`, but the sequence of the arguments is different
68
69
70### fs.write(file, content, options)
71
72#### options
73Type: `Object`
74
75The 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)
78Read a file
79
80#### options
81Type: `Object`
82
83The 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
86Type: `String`
87
88Default value: `fs.defaultEncoding`
89
90### fs.readJSON(file, options)
91Read 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
95Delete 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