# HG changeset patch # User Yaroslav Zhuravlev # Date 1602153379 -3600 # Node ID 99bd2ae8d2beb3b11995425bf552278551090bbd # Parent 249ae2577aac5ba8f7e4e1b4f74c02f409e8e87f Added Buffer to njs Reference. diff --git a/xml/en/docs/njs/reference.xml b/xml/en/docs/njs/reference.xml --- a/xml/en/docs/njs/reference.xml +++ b/xml/en/docs/njs/reference.xml @@ -872,6 +872,577 @@ clearTimeout(t);
+
+ + + + +Buffer.alloc(size[, +fill[, +encoding]])) + + +Allocates a new Buffer of a specified size. +If fill is not specified, the Buffer will be zero-filled. +If fill is specified, +the allocated Buffer will be initialized by calling +buf.fill(fill). +If fill and encoding are specified, +the allocated Buffer will be initialized by calling +buf.fill(fill, +encoding). + + + +The fill parameter may be a +string, +Buffer, +Uint8Array, or +integer. + + + +Buffer.allocUnsafe(size) + + +The same as +Buffer.alloc(), +with the difference that the memory allocated for the buffer is not initialized, +the contents of the new buffer is unknown and may contain sensitive data. + + + +Buffer.byteLength(value[, +encoding]) + +Returns the byte length of a specified value, +when encoded using encoding. +The value can be a +string, +Buffer, +TypedArray, +DataView, or +ArrayBuffer. +If the value is a string, +the encoding parameter is its encoding, can be +utf-8, +hex, +base64, +base64url; +by default is utf-8. + + +Buffer.compare(buffer1, +buffer2) + +Compares buffer1 with buffer2 +when sorting arrays of Buffer instances. +Returns +0 if +buffer1 is the same as buffer2, +1 if +buffer2 should come before buffer1 when sorted, or +-1 if +buffer2 should come after buffer1 when sorted. + + +Buffer.concat(list[, +totalLength]) + +Returns a new Buffer +which is the result of concatenating all the Buffer instances in the list. +If there are no items in the list or the total length is 0, +a new zero-length Buffer is returned. +If totalLength is not specified, +it is calculated from the Buffer instances in list by adding their lengths. +If totalLength is specified, +it is coerced to an unsigned integer. +If the combined length of the Buffers in list exceeds +totalLength, +the result is truncated to totalLength. + + +Buffer.from(array) + +Allocates a new Buffer using an array of bytes +in the range 0255. +Array entries outside that range will be truncated. + + +Buffer.from(buffer) + +Copies the passed buffer data onto a new Buffer instance. + + +Buffer.from(object[, +offsetOrEncoding[, +length]]) + +For objects whose valueOf() function +returns a value not strictly equal to object, +returns +Buffer.from(object.valueOf(), +offsetOrEncoding, +length). + + +Buffer.from(string[, +encoding]) + +Creates a new Buffer with a string. +The encoding parameter identifies the character encoding +to be used when converting a string into bytes. +The encoding can be +utf-8, +hex, +base64, +base64url; +by default is utf-8. + + +Buffer.isBuffer(object) + +A boolean value, +returns true if object is a Buffer. + + +Buffer.isEncoding(encoding) + +A boolean value, +returns true +if encoding is the name of a supported character encoding. + + +buffer[index] + +The index operator index +can be used to get and set the octet at position index in +buffer. +The values refer to individual bytes, +so the legal value range is between 0 and 255 (decimal). + + +buf.buffer + +The underlying ArrayBuffer object +based on which this Buffer object is created. + + +buf.byteOffset + +An integer, +specifying the byteOffset of the Buffers +underlying ArrayBuffer object. + + +buf.compare(target[, +targetStart[, +targetEnd[, +sourceStart[, +sourceEnd]]]]) + +Compares buffer with target and returns a number +indicating whether buffer comes before, after, or is the same +as target in sort order. +Comparison is based on the actual sequence of bytes in each Buffer. +The targetStart is an integer specifying the offset +within target at which to begin comparison, +by default is 0. +The targetEnd is an integer specifying the offset +within target at which to end comparison, +by default is target.length. +The sourceStart is an integer specifying the offset +within buffer at which to begin comparison, +by default is 0. +The sourceEnd is an integer specifying the offset +within buffer at which to end comparison (not inclusive), +by default is buf.length. + + +buf.copy(target[, +targetStart[, +sourceStart[, +sourceEnd]]]) + +Copies data from a region of buffer to a region in target, +even if the target memory region overlaps with buffer. +The target parameter is a +Buffer or Uint8Array to copy into. + + +The targetStart is an integer specifying the offset +within target at which to begin writing, +by default is 0. +The sourceStart is an integer specifying the offset +within buffer from which to begin copying, +by default is 0. +The sourceEnd is an integer specifying the offset +within buffer at which to stop copying (not inclusive) +by default is buf.length. + + + +buf.equals(otherBuffer) + +A boolean value, +returns true if both Buffer and otherBuffer +have exactly the same bytes. + + +buf.fill(value[, +offset[, +end]][, +encoding]) + +Fills the Buffer with the specified value. +If the offset and end are not specified, +the entire Buffer will be filled. +The value is coerced to uint32 if it is not a +string, +Buffer, or +integer. +If the resulting integer is greater than 255, +the Buffer will be filled with value and 255. + + +buf.includes(value[, +byteOffset][, +encoding]) + +Equivalent to +buf.indexOf() +!== -1, +returns true if the value was found +in Buffer. + + +buf.indexOf(value[, +byteOffset][, +encoding]) + +Returns an integer which is the index of the first occurrence of +value in Buffer, or -1 +if Buffer does not contain value. +The value can be a +string with specified encoding +(by default utf-8), +Buffer, +Unit8Array, +or a number between 0 and 255. + + +buf.lastIndexOf(value[, +byteOffset][, +encoding]) + +The same as +buf.indexOf(), +except the last occurrence of the value is found +instead of the first occurrence. +The value can be a string, Buffer, or +integer between 1 and 255. +If the value is an empty string or empty Buffer, +byteOffset will be returned. + + +buf.length + +Returns the number of bytes in Buffer. + + +buf.readIntBE(offset, +byteLength) + +Reads the byteLength from buf +at the specified offset +and interprets the result as a big-endian, +two's complement signed value supporting up to 48 bits of accuracy. +The byteLength parameter is an integer between 1 and 6 +specifying the number of bytes to read. + +The similar methods are also supported: +buf.readInt8([offset]), +buf.readInt16BE([offset]), +buf.readInt32BE([offset]). + + + +buf.readIntLE(offset, +byteLength) + +Reads the byteLength from buf +at the specified offset +and interprets the result as a little-endian, +two's complement signed value supporting up to 48 bits of accuracy. +The byteLength parameter is an integer between 1 and 6 +specifying the number of bytes to read. + +The similar methods are also supported: +buf.readInt8([offset]), +buf.readInt16LE([offset]), +buf.readInt32LE([offset]). + + + +buf.readUIntBE(offset, +byteLength) + +Reads the byteLength from buf +at the specified offset +and interprets the result as a big-endian +integer supporting up to 48 bits of accuracy. +The byteLength parameter is an integer between 1 and 6 +specifying the number of bytes to read. + +The similar methods are also supported: +buf.readUInt8([offset]), +buf.readUInt16BE([offset]), +buf.readUInt32BE([offset]). + + + +buf.readUIntLE(offset, +byteLength) + +Reads the byteLength from buf +at the specified offset +and interprets the result as a little-endian +integer supporting up to 48 bits of accuracy. +The byteLength parameter is an integer between 1 and 6 +specifying the number of bytes to read. + +The similar methods are also supported: +buf.readUInt8([offset]), +buf.readUInt16LE([offset]), +buf.readUInt32LE([offset]). + + + +buf.readDoubleBE([offset]) + +Reads a 64-bit, big-endian double from buf +at the specified offset. + + +buf.readDoubleLE([offset]) + +Reads a 64-bit, little-endian double from buf +at the specified offset. + + +buf.readFloatBE([offset]) + +Reads a 32-bit, big-endian float from buf +at the specified offset. + + +buf.readFloatLE([offset]) + +Reads a 32-bit, little-endian float from buf +at the specified offset. + + +buf.subarray[start[, +end]]) + +Returns a new buf +that references the same memory as the original, +but offset and cropped by +start and end. +If end is greater than +buf.length, +the same result as that of end equal to +buf.length +is returned. + + +buf.slice[start[, +end]]) + +Returns a new buf +that references the same memory as the original, +but offset and cropped by the +start and end values. +The method is not compatible with the +Uint8Array.prototype.slice(), +which is a superclass of Buffer. +To copy the slice, use +Uint8Array.prototype.slice(). + + +buf.swap16() + +Interprets buf as an array of unsigned 16-bit numbers +and swaps the byte order in-place. +Throws an error if +buf.length +is not a multiple of 2. + + +buf.swap32() + +Interprets buf as an array of unsigned 32-bit numbers +and swaps the byte order in-place. +Throws an error if +buf.length +is not a multiple of 4. + + +buf.swap64() + +Interprets buf as an array of 64-bit numbers +and swaps byte order in-place. +Throws an error if +buf.length +is not a multiple of 8. + + +buf.toJSON() + +Returns a JSON representation of buf. +JSON.stringify() +implicitly calls this function when stringifying a Buffer instance. + + +buf.toString([encoding[, +start[, +end]]]) + +Decodes buf to a string +according to the specified character encoding. +which can be utf-8, +hex, +base64, +base64url. +The start and end parameters +may be passed to decode only a subset of Buffer. + + +buf.write(string[, +offset[, +length]][, +encoding]) + +Writes a string to buf +at offset +according to the character encoding. +The length parameter is the number of bytes to write. +If Buffer did not contain enough space to fit the entire string, +only part of string will be written, +however, partially encoded characters will not be written. +The encoding can be +utf-8, +hex, +base64, +base64url. + + +buf.writeIntBE(value, +offset, +byteLength) + +Writes byteLength bytes of value +to buf +at the specified offset as big-endian. +Supports up to 48 bits of accuracy. +The byteLength parameter is an integer between 1 and 6 +specifying the number of bytes to read. + +The following similar methods are also supported: +buf.writeInt8, +buf.writeInt16BE, +buf.writeInt32BE. + + + +buf.writeIntLE(value, +offset, +byteLength) + +Writes byteLength bytes of value +to buf +at the specified offset as little-endian. +Supports up to 48 bits of accuracy. +The byteLength parameter is an integer between 1 and 6 +specifying the number of bytes to read. + +The following similar methods are also supported: +buf.writeInt8, +buf.writeInt16LE, +buf.writeInt32LE. + + + +buf.writeUIntBE(value, +offset, +byteLength) + +Writes byteLength bytes of value +to buf +at the specified offset as big-endian. +Supports up to 48 bits of accuracy. +The byteLength parameter is an integer between 1 and 6 +specifying the number of bytes to read. + +The following similar methods are also supported: +buf.writeUInt8, +buf.writeUInt16BE, +buf.writeUInt32BE. + + + +buf.writeUIntLE(value, +offset, +byteLength) + +Writes byteLength bytes of value +to buf +at the specified offset as little-endian. +Supports up to 48 bits of accuracy. +The byteLength parameter is an integer between 1 and 6 +specifying the number of bytes to read. + +The following similar methods are also supported: +buf.writeUInt8, +buf.writeUInt16LE, +buf.writeUInt32LE. + + + +buf.writeDoubleBE(value, +[offset]) + +Writes the value to buf +at the specified offset as big-endian. + + +buf.writeDoubleLE(value, +[offset]) + +Writes the value to buf +at the specified offset as little-endian. + + +buf.writeFloatBE(value, +[offset]) + +Writes the value to buf +at the specified offset as big-endian. + + +buf.writeFloatLE(value, +[offset]) + +Writes the value to buf +at the specified offset as little-endian. + + + + + +
+ +