Advertisement
Guest User

Italian Translation Report: Node.js [Part 26 - 1267 words]

a guest
Aug 14th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.61 KB | None | 0 0
  1. Prior to the introduction of, the JavaScript language had no mechanism for reading or manipulating streams of binary data.
  2. The class was introduced as part of the Node.js API to enable interaction with octet streams in TCP streams, file system operations, and other contexts.
  3. With now available, the class implements the API in a manner that is more optimized and suitable for Node.js.
  4. Instances of the class are similar to arrays of integers but correspond to fixed-sized, raw memory allocations outside the V8 heap.
  5. The size of the is established when it is created and cannot be changed.
  6. The class is within the global scope, making it unlikely that one would need to ever use
  7. // Creates a zero-filled Buffer of length 10.
  8. // Creates a Buffer of length 10, filled with 0x1.
  9. // Creates an uninitialized buffer of length 10.
  10. // This is faster than calling but the returned
  11. // Buffer instance might contain old data that needs to be
  12. // overwritten using either or
  13. // Creates a Buffer containing
  14. In versions of Node.js prior to 6.0.0, instances were created using the constructor function, which allocates the returned
  15. differently based on what arguments are provided:
  16. Passing a number as the first argument to (e.g.) allocates a new object of the specified size.
  17. Prior to Node.js 8.0.0, the memory allocated for such instances is not initialized and can contain sensitive data
  18. Such instances must be subsequently initialized by using either or by writing to the entire
  19. While this behavior is intentional to improve performance, development experience has demonstrated that a more explicit distinction is required between creating a fast-but-uninitialized versus creating a slower-but-safer
  20. Starting in Node.js 8.0.0, and will return a with initialized memory.
  21. Passing a string, array, or as the first argument copies the passed object's data into the
  22. Passing an or a returns a that shares allocated memory with the given array buffer.
  23. Because the behavior of is different depending on the type of the first argument, security and reliability issues can be inadvertently introduced into applications when argument validation or initialization is not performed.
  24. To make the creation of instances more reliable and less error-prone, the various forms of the constructor have been deprecated and replaced by separate, and methods.
  25. Developers should migrate all existing uses of the constructors to one of these new APIs.
  26. returns a new that contains a copy of the provided octets.
  27. returns a new that shares the same allocated memory as the given
  28. returns a new that contains a copy of the contents of the given
  29. returns a new initialized of the specified size.
  30. This method is slower than but guarantees that newly created instances never contain old data that is potentially sensitive.
  31. and each return a new uninitialized of the specified
  32. Because the is uninitialized, the allocated segment of memory might contain old data that is potentially sensitive.
  33. instances returned by may be allocated off a shared internal memory pool if is less than or equal to half
  34. Instances returned by never use the shared internal memory pool.
  35. Node.js can be started using the command line option to cause all newly allocated instances to be zero-filled upon creation by default, including buffers returned by and
  36. Use of this flag can have a significant negative impact on performance.
  37. Use of the option is recommended only when necessary to enforce that newly allocated instances cannot contain old data that is potentially sensitive.
  38. When calling and, the segment of allocated memory is uninitialized (it is not zeroed-out).
  39. While this design makes the allocation of memory quite fast, the allocated segment of memory might contain old data that is potentially sensitive.
  40. Using a created by without completely overwriting the memory can allow this old data to be leaked when the memory is read.
  41. While there are clear performance advantages to using extra care must be taken in order to avoid introducing security vulnerabilities into an application.
  42. The command line option
  43. What makes and "unsafe"?
  44. Buffers and Character Encodings
  45. When string data is stored in or extracted out of a instance, a character encoding may be specified.
  46. Prints
  47. The character encodings currently supported by Node.js include:
  48. For 7-bit ASCII data only.
  49. This encoding is fast and will strip the high bit if set.
  50. Multibyte encoded Unicode characters. Many web pages and other document formats use UTF-8.
  51. 2 or 4 bytes, little-endian encoded Unicode characters. Surrogate pairs are supported.
  52. Alias of
  53. Base64 encoding. When creating a from a string, this encoding will also correctly accept "URL and Filename Safe Alphabet" as specified in RFC4648, Section 5.
  54. A way of encoding the into a one-byte encoded string (as defined by the IANA in RFC1345, page 63, to be the Latin-1 supplement block and C0/C1 control codes).
  55. Encode each byte as two hexadecimal characters.
  56. Modern Web browsers follow the WHATWG Encoding Standard which aliases both and to. This means that while doing something like, if the returned charset is one of those listed in the WHATWG specification it is possible that the server actually returned encoded data, and using encoding may incorrectly decode the characters.
  57. and
  58. instances are also instances.
  59. However, there are subtle incompatibilities with
  60. For example, while creates a copy of the slice, the implementation of creates a view over the existing without copying, making far more efficient.
  61. It is also possible to create new instances from a with the following caveats:
  62. The object's memory is copied to the, not shared.
  63. The object's memory is interpreted as an array of distinct elements, and not as a byte array of the target type.
  64. That is, creates a 4-element with elements, not a with a single element or
  65. It is possible to create a new that shares the same allocated memory as a instance by using the object's property.
  66. Copies the contents of
  67. Shares memory with
  68. Note that when creating a using a, it is possible to use only a portion of the underlying by passing in and parameters.
  69. The and have different signatures and implementations.
  70. Specifically, the variants accept a second argument that is a mapping function that is invoked on every element of the typed array:
  71. The method, however, does not support the use of a mapping function:
  72. Buffers and iteration
  73. instances can be iterated over using syntax:
  74. Additionally, the, and methods can be used to create iterators.
  75. The class is a global type for dealing with binary data directly. It can be constructed in a variety of ways.
  76. Stability: 0 - Deprecated: Use instead.
  77. An array of bytes to copy from.
  78. Allocates a new using an of octets.
  79. Creates a new Buffer containing the UTF-8 bytes of the string
  80. An or the property of a
  81. Index of first byte to expose.
  82. Number of bytes to expose.
  83. This creates a view of the or without copying the underlying memory.
  84. For example, when passed a reference to the property of a instance, the newly created will share the same allocated memory as the
  85. The optional and arguments specify a memory range within the that will be shared by the
  86. Changing the original changes the Buffer also
  87. An existing or from which to copy data.
  88. Copies the passed data onto a new instance.
  89. The desired length of the new
  90. Allocates a new of bytes.
  91. If is larger than or smaller than 0, is
  92. A zero-length is created if is 0.
  93. Prior to Node.js 8.0.0, the underlying memory for instances created in this way is not initialized
  94. The contents of a newly created are unknown and may contain sensitive data
  95. Use instead to initialize a with zeroes.
  96. String to encode.
  97. The encoding of
  98. Creates a new containing
  99. The parameter identifies the character encoding of
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement