web 3d图形渲染器
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.

70 lines
2.4 KiB

  1. # fs-minipass
  2. Filesystem streams based on [minipass](http://npm.im/minipass).
  3. 4 classes are exported:
  4. - ReadStream
  5. - ReadStreamSync
  6. - WriteStream
  7. - WriteStreamSync
  8. When using `ReadStreamSync`, all of the data is made available
  9. immediately upon consuming the stream. Nothing is buffered in memory
  10. when the stream is constructed. If the stream is piped to a writer,
  11. then it will synchronously `read()` and emit data into the writer as
  12. fast as the writer can consume it. (That is, it will respect
  13. backpressure.) If you call `stream.read()` then it will read the
  14. entire file and return the contents.
  15. When using `WriteStreamSync`, every write is flushed to the file
  16. synchronously. If your writes all come in a single tick, then it'll
  17. write it all out in a single tick. It's as synchronous as you are.
  18. The async versions work much like their node builtin counterparts,
  19. with the exception of introducing significantly less Stream machinery
  20. overhead.
  21. ## USAGE
  22. It's just streams, you pipe them or read() them or write() to them.
  23. ```js
  24. const fsm = require('fs-minipass')
  25. const readStream = new fsm.ReadStream('file.txt')
  26. const writeStream = new fsm.WriteStream('output.txt')
  27. writeStream.write('some file header or whatever\n')
  28. readStream.pipe(writeStream)
  29. ```
  30. ## ReadStream(path, options)
  31. Path string is required, but somewhat irrelevant if an open file
  32. descriptor is passed in as an option.
  33. Options:
  34. - `fd` Pass in a numeric file descriptor, if the file is already open.
  35. - `readSize` The size of reads to do, defaults to 16MB
  36. - `size` The size of the file, if known. Prevents zero-byte read()
  37. call at the end.
  38. - `autoClose` Set to `false` to prevent the file descriptor from being
  39. closed when the file is done being read.
  40. ## WriteStream(path, options)
  41. Path string is required, but somewhat irrelevant if an open file
  42. descriptor is passed in as an option.
  43. Options:
  44. - `fd` Pass in a numeric file descriptor, if the file is already open.
  45. - `mode` The mode to create the file with. Defaults to `0o666`.
  46. - `start` The position in the file to start reading. If not
  47. specified, then the file will start writing at position zero, and be
  48. truncated by default.
  49. - `autoClose` Set to `false` to prevent the file descriptor from being
  50. closed when the stream is ended.
  51. - `flags` Flags to use when opening the file. Irrelevant if `fd` is
  52. passed in, since file won't be opened in that case. Defaults to
  53. `'a'` if a `pos` is specified, or `'w'` otherwise.