buffer
Object buffer
Binary data cache object for IO read-write data processing
Buffer object is global basic class, can be created with new Buffer(…) by anytime:
1 | var buf = new Buffer(); |
Static function
isBuffer
Detects whether a given variable is a Buffer object
1 | Buffer.isBuffer(v); |
Parameter Usage:
- v: Value, Give the variables to detect
Results:
- Boolean, Whether the incoming object is a Buffer object
Example:
1 | exports.hi = v => { |
from
Use other Buffer to create Buffer object
1 | Buffer.from(buffer,byteOffset,length); |
Parameter Usage:
- buffer: Buffer, A Buffer type variable is given to create a Buffer object
- byteOffset: Integer, Specifies the data start position, start with 0
- length: Integer, Specify data length,start with -1,Represents all the remaining data
Results:
- Buffer, Return Buffer Example
Example:
1 | exports.hi = v => { |
Use string to create Buffer object
1 | Buffer.from(str,byteOffset,length); |
Parameter Usage:
- str: String, Initialize string,the string will be written in format utf-8
- byteOffset: Integer, Specifies the data start position,start with 0
- length: Integer, Specify data length,start with -1,Represents all the remaining data
Results:
- Buffer, Return Buffer Example
Example:
1 | exports.hi = v => { |
Use string to create Buffer object
1 | Buffer.from(str,codec); |
Parameter Usage:
- str: String, Initializing string,the string will be written in format utf-8, default is to create a empty object.
- codec: String, Specifies the encoding format with an allowable value of:”hex”, “base64”, “utf8”, Or the character sets supported by the system
Results:
- Buffer, Return Buffer Example
Example:
1 | exports.hi = v => { |
concat
Concatenate data in multiple cache regions
1 | Buffer.concat(buflist,cutLength); |
Parameter Usage:
- buflist: Array, Buffer array to be spliced
- cutLength: Integer, How many Buffer objects to intercept
Results:
- Buffer, new Buffer object spliced result
Example:
1 | exports.hi = v => { |
alloc
Allocates a new cache area of specified length. If the size is 0, a zero-length buffer is created.
1 | Buffer.alloc(size,fill,codec); |
Parameter Usage:
- size: Integer, The required length of the buffer
- fill: Integer, Prepopulate the value of the new buffer, string/buffer/integer value types can be used Default:0
- codec: String, Specifies the encoding format with an allowable value of:”hex”, “base64”, “utf8”, Or the character sets supported by the system
Results:
- Buffer, Populates the new Buffer object
Example:
1 | exports.hi = v => { |
Allocates a new cache area of specified length. If the size is 0, a zero-length buffer is created.
1 | Buffer Buffer.alloc(size,fill,codec); |
Parameter Usage:
- size: Integer, The required length of the buffer
- fill: String, Prepopulate the value of the new buffer,string/buffer/integer value types can be used. Default:0
- codec: String, Specifies the encoding format with an allowable value of:”hex”, “base64”, “utf8”, Or the character sets supported by the system
Results:
- Buffer, Populates the new Buffer object
Example:
1 | exports.hi = v => { |
Allocates a new cache area of specified length. If the size is 0, a zero-length buffer is created.
1 | Buffer.alloc(size,fill,codec); |
Parameter Usage:
- size: Integer, The required length of the buffer
- fill: Buffer, Prepopulate the value of the new buffer, string/buffer/integer value types can be used. Default:0
- codec: String, Specifies the encoding format with an allowable value of:”hex”, “base64”, “utf8”, Or the character sets supported by the system
Results:
- Buffer, Populates the new Buffer object
Example:
1 | exports.hi = v => { |
allocUnsafe
Allocates a new cache area of specified length. If the size is 0, a zero-length buffer is created.
1 | Buffer.allocUnsafe(size); |
Parameter Usage:
- size: Integer, The required length of the buffer
Results:
- Buffer, Specifies the size of the new Buffer object
Example:
1 | exports.hi = v => { |
allocUnsafeSlow
Allocates a new cache area of specified length. If the size is 0, a zero-length buffer is created.
1 | Buffer.allocUnsafeSlow(size); |
Parameter Usage:
- size: Integer, The required length of the buffer
Results:
- Buffer, Specifies the size of the new Buffer object
Example:
1 | exports.hi = v => { |
isEncoding
Check whether the encoding format is supported
1 | Buffer.isEncoding(codec); |
Parameter Usage:
- codec: String, Encoding format to be check
Results:
- Boolean, wether it is supported
Example:
1 | exports.hi = v => { |
Member attribute
length
Integer, Get the size of the cached object
1 | readonly Integer Buffer.length; |
member function
Buffer
Cache object constructors
1 | Buffer.Buffer(Array datas); |
Parameter Usage:
- datas: Array, Initialize the data array
1 | exports.hi = v => { |
Cache object constructors
1 | Buffer.Buffer(ArrayBuffer datas); |
Parameter Usage:
- datas: ArrayBuffer, Initialize the data array
1 | exports.hi = v => { |
Cache object constructors
1 | Buffer.Buffer(TypedArray datas); |
Parameter Usage:
- datas: TypedArray, Initializes the data array
1 | exports.hi = v => { |
Cache object constructors
1 | Buffer.Buffer(ArrayBufferView datas); |
Parameter Usage:
- datas: ArrayBufferView, Initialize the data array
1 | exports.hi = v => { |
Cache object constructors
1 | Buffer.Buffer(Buffer buffer); |
Parameter Usage:
- buffer: Buffer, Initialize the buffer object
1 | exports.hi = v => { |
Cache object constructors
1 | Buffer.Buffer(String str, |
Parameter Usage:
- str: String, Initialize string,the string will be written in by the format of utf-8,default is to create an empty object.
- codec: String, Specifies the encoding format with an allowable value of:”hex”, “base64”, “utf8”, Or the character sets supported by the system
1 | exports.hi = v => { |
Cache object constructors
1 | Buffer.Buffer(Integer size = 0); |
Parameter Usage:
- size: Integer, Initialize size of buffer area
Example:
1 | exports.hi = v => { |
resize
resize cached object
1 | Buffer.resize(Integer sz); |
Parameter Usage:
- sz: Integer, give a new size
Example:
1 | exports.hi = v => { |
append
Write a binary array in the end of cached object
1 | Buffer.append(Buffer data); |
Parameter Usage:
- data: Buffer, Initialize binary data
Example:
1 | exports.hi = v => { |
Write a string at the end of the cached object, which is written in utf-8 format
1 | Buffer.append(String str, |
Parameter Usage:
- str: String, strings need to be written
- codec: String, Specifies the encoding format with an allowable value of:”hex”, “base64”, “utf8”, Or the character sets supported by the system
Example:
1 | exports.hi = v => { |
write
Write specific string to cached object, default string is utf-8, Only part of the data is written when the boundary is crossed
1 | Integer Buffer.write(String str, |
Parameter Usage:
- str: String, The string to be written
- offset: Integer, Write start point
- length: Integer, Write lenth(Unit of byte,Default-1),The length of the string to be written if not specified
- codec: String, Specifies the encoding format with an allowable value of:”hex”, “base64”, “utf8”, Or the character sets supported by the system
Results:
- Integer, The length of written data byte
Example:
1 | exports.hi = v => { |
Write specific string to cached object, default string is utf-8, Only part of the data is written when the boundary is crossed
1 | Integer Buffer.write(String str, |
Parameter Usage:
- str: String, The string to be written
- offset: Integer, Write start point
- codec: String, Specifies the encoding format with an allowable value of:”hex”, “base64”, “utf8”, Or the character sets supported by the system
Results:
- Integer, The length of written data byte
Example:
1 | exports.hi = v => { |
Write specific string to cached object, default string is utf-8, Only part of the data is written when the boundary is crossed
1 | Integer Buffer.write(String str, |
Parameter Usage:
- str: String, The string to be written
- codec: String, Specifies the encoding format with an allowable value of:”hex”, “base64”, “utf8”, Or the character sets supported by the system
Results:
- Integer, The length of written data byte
Example:
1 | exports.hi = v => { |
fill
Fill in specific content data to buffer object
1 | Buffer Buffer.fill(Integer v, |
Parameter Usage:
- v: Integer, Data that needs to be populated. If offset and end are not specified, the buffer is filled
- offset: Integer, fill in starting point
- end: Integer, fill in ending point
Results:
- Buffer, Return current Buffer object
Example:
1 | exports.hi = v => { |
Fill in specific content data to buffer object
1 | Buffer Buffer.fill(Buffer v, |
Parameter Usage:
- v: Buffer, Data that needs to be populated. If offset and end are not specified, the buffer is filled
- offset: Integer, fill in starting point
- end: Integer, fill in ending point
Results:
- Buffer, Return current Buffer object
Example:
1 | exports.hi = v => { |
Fill in specific content data to buffer object
1 | Buffer Buffer.fill(String v, |
Parameter Usage:
- v: String, Data that needs to be populated. If offset and end are not specified, the buffer is filled
- offset: Integer, Write starting position
- end: Integer, Write ending position
Results:
- Buffer, Return current Buffer object
Example:
1 | exports.hi = v => { |
indexOf
Return the location in Buffer where the specificdata first appears
1 | Integer Buffer.indexOf(Integer v, |
Parameter Usage:
- v: Integer, Data to be looked up,if offset is not defined,start from starting point by default
- offset: Integer, Initial search location
Results:
- Integer, Return the location found,Return -1 if Not found
Example:
1 | exports.hi = v => { |
Return the location in Buffer where the specificdata first appears
1 | Integer Buffer.indexOf(String v, |
Parameter Usage:
- v: String, Data to be looked up,if offset is not defined,start from starting point by default
- offset: Integer, Find starting location
Results:
- Integer, Return the location found,Return -1 if Not found
Example:
1 | exports.hi = v => { |
compare
Compares the contents of the cache area
1 | Integer Buffer.compare(Buffer buf); |
Parameter Usage:
- buf: Buffer, Cache objects to be compared
Results:
- Integer, Content comparison results
Example:
1 | exports.hi = v => { |
copy
Copy data from the source cache object region to the target cache object region
1 | Integer Buffer.copy(Buffer targetBuffer, |
Parameter Usage:
- targetBuffer: Buffer, Target cache object
- targetStart: Integer, The target cache object begins copying the byte location,default is 0
- sourceStart: Integer, Source cache object starting byte location, default is 0
- sourceEnd: Integer, Source cache object ending byte location, default is -1, Represents the length of the source data
Results:
- Integer, copy the length of the data bytes
Example:
1 | exports.hi = v => { |
slice
Return a new cache object,Contains data that specifies the start to end of the cache
1 | Buffer Buffer.slice(Integer start = 0); |
Parameter Usage:
- start: Integer, Specifies the start of the range, starting from scratch by default
Results:
- Buffer, Return a new cache object
Example:
1 | exports.hi = v => { |
Return a new cache object,Contains data for the specified range, and returns only a valid portion of the data if the range exceeds the cache
1 | Buffer Buffer.slice(Integer start, |
Parameter Usage:
- start: Integer, Specifies the start of the range
- end: Integer, Specifies the end of the range
Results:
- Buffer, Return a new cache objecrt
Example:
1 | exports.hi = v => { |
join
Puts all elements of the current object into a string
1 | String Buffer.join(String separator = ","); |
Parameter Usage:
- separator: String, split string,default is “,”
Results:
- String, Return generated data
Example:
1 | exports.hi = v => { |
reverse
Return a new cache object,Contains the inverted order of the current object data
1 | Buffer Buffer.reverse(); |
Results:
- Buffer, Return new cache object
Example:
1 | exports.hi = v => { |
equals
Compares whether the current object is equal to a given object
1 | Boolean Buffer.equals(object expected); |
Parameter Usage:
- expected: object, Set goals for comparison
Results:
- Boolean, Return objects comparing results
Example:
1 | exports.hi = v => { |
hex
Use hex to cache object content
1 | String Buffer.hex(); |
Results:
- String, Return encoding string
base64
use base64 encodes to cache object content
1 | String Buffer.base64(); |
Results:
- String, Return encoding string
keys
Return all arrays of binary data
1 | Iterator Buffer.keys(); |
Results:
- Iterator, Return iterator includes object data index
values
Return all arrays of binary data
1 | Iterator Buffer.values(); |
Results:
- Iterator, Return iterator includes object data index
entries
Return including object data [index, byte] Right iterator
1 | Iterator Buffer.entries(); |
Results:
- Iterator, [index, byte] Right iterator
toArray
Return all arrays of binary data
1 | Array Buffer.toArray(); |
Results:
- Array, Return arrays includes data object
Example:
1 | exports.hi = v => { |
toString
Return encoding string of binary data
1 | String Buffer.toString(String codec, |
Parameter Usage:
- codec: String, Specifies the encoding format with an allowable value of:”hex”, “base64”, “utf8”, Or the character sets supported by the system
- offset: Integer, read starting point
- end: Integer, read ending point
Results:
- String, Return string of the object
Example:
1 | exports.hi = v => { |
Return encoding string of binary data
1 | String Buffer.toString(String codec, |
Parameter Usage:
- codec: String, Specifies the encoding format with an allowable value of:”hex”, “base64”, “utf8”, Or the character sets supported by the system
- offset: Integer, read start point.
Results:
- String, Return string of the object
Example:
1 | exports.hi = v => { |
Return binary utf8 string
1 | String Buffer.toString(); |
Results:
- String, Return string of the object
Example:
1 | exports.hi = v => { |
toJSON
Return JSON format of the object,Return a collection of readable properties defined by an object
1 | String Buffer.toJSON(); |
Results:
- String, Return JSON format of the object
Example:
1 | exports.hi = v => { |
