Advertisement
robertbira

Italian Translation Report: Node.js [Part 21 - 1150 words]

Aug 6th, 2018
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.55 KB | None | 0 0
  1. If a call to returns, the event will be emitted when it is appropriate to resume writing data to the stream.
  2. // Write the data to the supplied writable stream one million times.
  3. // Be attentive to back-pressure.
  4. // last time!
  5. // see if we should continue, or wait
  6. // don't pass the callback, because we're not done yet.
  7. // had to stop early!
  8. // write some more once it drains
  9. The event is emitted if an error occurred while writing or piping data.
  10. The listener callback is passed a single argument when called.
  11. The stream is not closed when the event is emitted.
  12. The event is emitted after the method has been called, and all data has been flushed to the underlying system.
  13. source stream that is piping to this writable
  14. The event is emitted when the method is called on a readable stream, adding this writable to its set of destinations.
  15. The source stream that this writable
  16. The event is emitted when the method is called on a stream, removing this from its set of destinations.
  17. This is also emitted in case this stream emits an error when a stream pipes into it.
  18. The method forces all written data to be buffered in memory.
  19. The buffered data will be flushed when either the or methods are called.
  20. The primary intent of is to avoid a situation where writing many small chunks of data to a stream do not cause a backup in the internal buffer that would have an adverse impact on performance.
  21. In such situations, implementations that implement the method can perform buffered writes in a more optimized manner.
  22. See also:
  23. Returns:
  24. Destroy the stream, and emit the passed and a event.
  25. After this call, the writable stream has ended and subsequent calls to will give an error.
  26. Implementors should not override this method, but instead implement
  27. Optional data to write.
  28. For streams not operating in object mode, must be a string, or
  29. For object mode streams, may be any JavaScript value other than
  30. The encoding, if is a string
  31. Optional callback for when the stream is finished
  32. Calling the method signals that no more data will be written to the
  33. The optional and arguments allow one final additional chunk of data to be written immediately before closing the stream.
  34. If provided, the optional function is attached as a listener for the event.
  35. Calling the method after calling will raise an error.
  36. write and then end with
  37. writing more now is not allowed
  38. The method sets the default for a stream.
  39. The method flushes all data buffered since was called.
  40. When using and to manage the buffering of writes to a stream, it is recommended that calls to be deferred using
  41. Doing so allows batching of all calls that occur within a given Node.js event loop phase.
  42. If the method is called multiple times on a stream, the same number of calls to must be called to flush the buffered data.
  43. The data will not be flushed until is called a second time.
  44. Return the value of passed when constructing this
  45. This property contains the number of bytes (or objects) in the queue ready to be written.
  46. The value provides introspection data regarding the status of the
  47. Callback for when this chunk of data is flushed
  48. if the stream wishes for the calling code to wait for the event to be emitted before continuing to write additional data; otherwise
  49. The method writes some data to the stream, and calls the supplied once the data has been fully handled.
  50. If an error occurs, the may or may not be called with the error as its first argument.
  51. To reliably detect write errors, add a listener for the event.
  52. The return value is if the internal buffer is less than the configured when the stream was created after admitting
  53. If is returned, further attempts to write data to the stream should stop until the event is emitted.
  54. While a stream is not draining, calls to will buffer, and return false.
  55. Once all currently buffered chunks are drained (accepted for delivery by the operating system), the event will be emitted.
  56. It is recommended that once returns false, no more chunks be written until the event is emitted.
  57. Even before it aborts, high memory usage will cause poor garbage collector performance and high RSS (which is not typically released back to the system, even after the memory is no longer required).
  58. Since TCP sockets may never drain if the remote peer does not read the data, writing a socket that is not draining may lead to a remotely exploitable vulnerability.
  59. Writing data while the stream is not draining is particularly problematic for a, because the streams are paused by default until they are piped or an or event handler is added.
  60. If the data to be written can be generated or fetched on demand, it is recommended to encapsulate the logic into a and use
  61. However, if calling is preferred, it is possible to respect backpressure and avoid memory issues using the event:
  62. Wait for cb to be called before doing any other write.
  63. A stream in object mode will always ignore the argument.
  64. Readable streams are an abstraction for a from which data is consumed.
  65. Examples of streams include:
  66. HTTP responses, on the client
  67. HTTP requests, on the server
  68. All streams implement the interface defined by the class.
  69. Two Modes
  70. streams effectively operate in one of two modes: flowing and paused.
  71. When in flowing mode, data is read from the underlying system automatically and provided to an application as quickly as possible using events via the interface.
  72. In paused mode, the method must be called explicitly to read chunks of data from the stream.
  73. All streams begin in paused mode but can be switched to flowing mode in one of the following ways:
  74. Adding a event handler.
  75. Calling the method.
  76. Calling the method to send the data to a
  77. The can switch back to paused mode using one of the following:
  78. If there are no pipe destinations, by calling the method.
  79. If there are pipe destinations, by removing all pipe destinations.
  80. Multiple pipe destinations may be removed by calling the method.
  81. The important concept to remember is that a will not generate data until a mechanism for either consuming or ignoring that data is provided.
  82. If the consuming mechanism is disabled or taken away, the will attempt to stop generating the data.
  83. For backwards compatibility reasons, removing event handlers will not automatically pause the stream.
  84. Also, if there are piped destinations, then calling will not guarantee that the stream will paused once those destinations drain and ask for more data.
  85. If a is switched into flowing mode and there are no consumers available to handle the data, that data will be lost.
  86. This can occur, for
  87. instance, when the method is called without a listener attached to the event, or when a event handler is removed from the stream.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement