Initial commit
[yaffs-website] / node_modules / fstream / README.md
1 Like FS streams, but with stat on them, and supporting directories and
2 symbolic links, as well as normal files.  Also, you can use this to set
3 the stats on a file, even if you don't change its contents, or to create
4 a symlink, etc.
5
6 So, for example, you can "write" a directory, and it'll call `mkdir`.  You
7 can specify a uid and gid, and it'll call `chown`.  You can specify a
8 `mtime` and `atime`, and it'll call `utimes`.  You can call it a symlink
9 and provide a `linkpath` and it'll call `symlink`.
10
11 Note that it won't automatically resolve symbolic links.  So, if you
12 call `fstream.Reader('/some/symlink')` then you'll get an object
13 that stats and then ends immediately (since it has no data).  To follow
14 symbolic links, do this: `fstream.Reader({path:'/some/symlink', follow:
15 true })`.
16
17 There are various checks to make sure that the bytes emitted are the
18 same as the intended size, if the size is set.
19
20 ## Examples
21
22 ```javascript
23 fstream
24   .Writer({ path: "path/to/file"
25           , mode: 0755
26           , size: 6
27           })
28   .write("hello\n")
29   .end()
30 ```
31
32 This will create the directories if they're missing, and then write
33 `hello\n` into the file, chmod it to 0755, and assert that 6 bytes have
34 been written when it's done.
35
36 ```javascript
37 fstream
38   .Writer({ path: "path/to/file"
39           , mode: 0755
40           , size: 6
41           , flags: "a"
42           })
43   .write("hello\n")
44   .end()
45 ```
46
47 You can pass flags in, if you want to append to a file.
48
49 ```javascript
50 fstream
51   .Writer({ path: "path/to/symlink"
52           , linkpath: "./file"
53           , SymbolicLink: true
54           , mode: "0755" // octal strings supported
55           })
56   .end()
57 ```
58
59 If isSymbolicLink is a function, it'll be called, and if it returns
60 true, then it'll treat it as a symlink.  If it's not a function, then
61 any truish value will make a symlink, or you can set `type:
62 'SymbolicLink'`, which does the same thing.
63
64 Note that the linkpath is relative to the symbolic link location, not
65 the parent dir or cwd.
66
67 ```javascript
68 fstream
69   .Reader("path/to/dir")
70   .pipe(fstream.Writer("path/to/other/dir"))
71 ```
72
73 This will do like `cp -Rp path/to/dir path/to/other/dir`.  If the other
74 dir exists and isn't a directory, then it'll emit an error.  It'll also
75 set the uid, gid, mode, etc. to be identical.  In this way, it's more
76 like `rsync -a` than simply a copy.