You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

пре 3 година
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. So, for example, you can "write" a directory, and it'll call `mkdir`. You
  6. can specify a uid and gid, and it'll call `chown`. You can specify a
  7. `mtime` and `atime`, and it'll call `utimes`. You can call it a symlink
  8. and provide a `linkpath` and it'll call `symlink`.
  9. Note that it won't automatically resolve symbolic links. So, if you
  10. call `fstream.Reader('/some/symlink')` then you'll get an object
  11. that stats and then ends immediately (since it has no data). To follow
  12. symbolic links, do this: `fstream.Reader({path:'/some/symlink', follow:
  13. true })`.
  14. There are various checks to make sure that the bytes emitted are the
  15. same as the intended size, if the size is set.
  16. ## Examples
  17. ```javascript
  18. fstream
  19. .Writer({ path: "path/to/file"
  20. , mode: 0755
  21. , size: 6
  22. })
  23. .write("hello\n")
  24. .end()
  25. ```
  26. This will create the directories if they're missing, and then write
  27. `hello\n` into the file, chmod it to 0755, and assert that 6 bytes have
  28. been written when it's done.
  29. ```javascript
  30. fstream
  31. .Writer({ path: "path/to/file"
  32. , mode: 0755
  33. , size: 6
  34. , flags: "a"
  35. })
  36. .write("hello\n")
  37. .end()
  38. ```
  39. You can pass flags in, if you want to append to a file.
  40. ```javascript
  41. fstream
  42. .Writer({ path: "path/to/symlink"
  43. , linkpath: "./file"
  44. , SymbolicLink: true
  45. , mode: "0755" // octal strings supported
  46. })
  47. .end()
  48. ```
  49. If isSymbolicLink is a function, it'll be called, and if it returns
  50. true, then it'll treat it as a symlink. If it's not a function, then
  51. any truish value will make a symlink, or you can set `type:
  52. 'SymbolicLink'`, which does the same thing.
  53. Note that the linkpath is relative to the symbolic link location, not
  54. the parent dir or cwd.
  55. ```javascript
  56. fstream
  57. .Reader("path/to/dir")
  58. .pipe(fstream.Writer("path/to/other/dir"))
  59. ```
  60. This will do like `cp -Rp path/to/dir path/to/other/dir`. If the other
  61. dir exists and isn't a directory, then it'll emit an error. It'll also
  62. set the uid, gid, mode, etc. to be identical. In this way, it's more
  63. like `rsync -a` than simply a copy.