Italian Translation Report: Node.js [Part 24 - 1124 words]

Aug 10th, 2018
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Errors While Writing
  2. It is recommended that errors occurring during the processing of the and methods are reported by invoking the callback and passing the error as the first argument.
  3. This will cause an event to be emitted by the
  4. Throwing an from within can result in unexpected and inconsistent behavior depending on how the stream is being used.
  5. Using the callback ensures consistent and predictable handling of errors.
  6. If a stream pipes into a stream when emits an error, the stream will be unpiped.
  7. An Example Writable Stream
  8. The following illustrates a rather simplistic (and somewhat pointless) custom stream implementation.
  9. While this specific stream instance is not of any real particular usefulness, the example illustrates each of the required elements of a custom stream instance:
  10. Decoding buffers in a Writable Stream
  11. Decoding buffers is a common task, for instance, when using transformers whose input is a string.
  12. This is not a trivial process when using multi-byte characters encoding, such as UTF-8.
  13. The following example shows how to decode multi-byte strings using and
  14. currency
  15. Implementing a Readable Stream
  16. The class is extended to implement a stream.
  17. Custom streams must call the constructor and implement the method.
  18. The maximum number of bytes to store in the internal buffer before ceasing to read from the underlying resource.
  19. If specified, then buffers will be decoded to strings using the specified encoding.
  20. Whether this stream should behave as a stream of objects.
  21. Meaning that returns a single value instead of a of size
  22. Implementation for the method.
  23. Number of bytes to read asynchronously
  24. It should be implemented by child classes, and called by the internal class methods only.
  25. All stream implementations must provide an implementation of the method to fetch data from the underlying resource.
  26. When is called, if data is available from the resource, the implementation should begin pushing that data into the read queue using the method.
  27. should continue reading from the resource and pushing data until returns
  28. Only when is called again after it has stopped should it resume pushing additional data onto the queue.
  29. Once the method has been called, it will not be called again until the method is called.
  30. is guaranteed to be called only once within a synchronous execution, i.e. a microtick.
  31. The argument is advisory.
  32. For implementations where a "read" is a single operation that returns data can use the argument to determine how much data to fetch.
  33. Other implementations may ignore this argument and simply provide data whenever it becomes available.
  34. There is no need to "wait" until bytes are available before calling
  35. The method is prefixed with an underscore because it is internal to the class that defines it, and should never be called directly by user programs.
  36. Chunk of data to push into the read queue.
  37. For streams not operating in object mode, must be a string, or
  38. For object mode streams, may be any JavaScript value.
  39. Encoding of string chunks.
  40. Must be a valid encoding, such as or
  41. if additional chunks of data may continued to be pushed; otherwise.
  42. When is a, or, the of data will be added to the internal queue for users of the stream to consume.
  43. Passing as signals the end of the stream (EOF), after which no more data can be written.
  44. When the is operating in paused mode, the data added with can be read out by calling the method when the event is emitted.
  45. When the is operating in flowing mode, the data added with will be delivered by emitting a event.
  46. The method is designed to be as flexible as possible.
  47. For example, when wrapping a lower-level source that provides some form of pause/resume mechanism, and a data callback, the low-level source can be wrapped by the custom instance as illustrated in the following example:
  48. source is an object with and methods, and an member that gets called when it has data, and an member that gets called when the data is over.
  49. Every time there's data, push it into the internal buffer.
  50. if returns, then stop reading from source
  51. When the source ends, push the EOF-signaling chunk
  52. will be called when the stream wants to pull more data in
  53. the advisory size argument is ignored in this case.
  54. The method is intended be called only by implementers, and only from within the method.
  55. For streams not operating in object mode, if the parameter of is, it will be treated as empty string or buffer.
  56. See for more information.
  57. Errors While Reading
  58. It is recommended that errors occurring during the processing of the method are emitted using the event rather than being thrown.
  59. Throwing an from within can result in unexpected and inconsistent behavior depending on whether the stream is operating in flowing or paused mode.
  60. Using the event ensures consistent and predictable handling of errors.
  61. do some work
  62. An Example Counting Stream
  63. The following is a basic example of a stream that emits the numerals from 1 to 1,000,000 in ascending order, and then ends.
  64. Implementing a Duplex Stream
  65. A stream is one that implements both and such as a TCP socket connection.
  66. Because JavaScript does not have support for multiple inheritance, the class is extended to implement a stream (as opposed
  67. to extending the and classes).
  68. The class prototypically inherits from and parasitically from, but will work properly for both base classes due to overriding on
  69. Custom streams must call the constructor and implement both the and methods.
  70. Passed to both and constructors.
  71. Also has the following fields:
  72. If set to, then the stream will automatically end the writable side when the readable side ends.
  73. Sets for readable side of the stream.
  74. Has no effect if is
  75. An Example Duplex Stream
  76. The following illustrates a simple example of a stream that wraps a hypothetical lower-level source object to which data can be written, and from which data can be read, albeit using an API that is not compatible with Node.js streams.
  77. The following illustrates a simple example of a stream that buffers incoming written data via the interface that is read back out via the interface.
  78. The underlying source only deals with strings
  79. The most important aspect of a stream is that the and sides operate independently of one another despite co-existing within a single object instance.
  80. Object Mode Duplex Streams
  81. For streams, can be set exclusively for either the or side using the and options respectively.
  82. In the following example, for instance, a new stream (which is a type of stream) is created that has an object mode side that accepts JavaScript numbers that are converted to hexadecimal strings on the side.
  83. Coerce the chunk to a number if necessary
  84. Transform the chunk into something else.
  85. Push the data onto the readable queue.
  86. Prints
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add to your ad blocker whitelist or disable your adblocking software.