object Buffer extends Object
- Annotations
- @native() @JSGlobal()
- Alphabetic
- By Inheritance
- Buffer
- Object
- Any
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
val
INSPECT_MAX_BYTES: Int
Returns the maximum number of bytes that will be returned when buf.inspect() is called.
Returns the maximum number of bytes that will be returned when buf.inspect() is called. This can be overridden by user modules. See util.inspect() for more details on buf.inspect() behavior.
Note that this is a property on the buffer module returned by require('buffer'), not on the Buffer global or a Buffer instance.
-
def
alloc(size: Int, fill: |[|[Buffer, Int], String] = js.native, encoding: String = js.native): Buffer
Allocates a new Buffer of size bytes.
Allocates a new Buffer of size bytes. If fill is undefined, the Buffer will be zero-filled.
- size
The desired length of the new Buffer
- fill
A value to pre-fill the new Buffer with. Default: 0
- encoding
If fill is a string, this is its encoding. Default: 'utf8'
- returns
a new Buffer
Buffer.alloc(size[, fill[, encoding]])
Example: -
def
allocUnsafe(size: Int): Buffer
Calling Buffer.alloc(size) can be significantly slower than the alternative Buffer.allocUnsafe(size) but ensures that the newly created Buffer instance contents will never contain sensitive data.
Calling Buffer.alloc(size) can be significantly slower than the alternative Buffer.allocUnsafe(size) but ensures that the newly created Buffer instance contents will never contain sensitive data.
- size
the allocated size.
Buffer.allocUnsafe(size)
Example: -
def
allocUnsafeSlow(size: Int): Buffer
Allocates a new non-zero-filled and non-pooled Buffer of size bytes.
Allocates a new non-zero-filled and non-pooled Buffer of size bytes. The size must be less than or equal to the value of require('buffer').kMaxLength (on 64-bit architectures, kMaxLength is
(2^31)-1).
Otherwise, a RangeError is thrown. A zero-length Buffer will be created if a size less than or equal to 0 is specified.
The underlying memory for Buffer instances created in this way is not initialized. The contents of the newly created Buffer are unknown and may contain sensitive data. Use buf.fill(0) to initialize such Buffer instances to zeroes.
When using Buffer.allocUnsafe() to allocate new Buffer instances, allocations under 4KB are, by default, sliced from a single pre-allocated Buffer. This allows applications to avoid the garbage collection overhead of creating many individually allocated Buffers. This approach improves both performance and memory usage by eliminating the need to track and cleanup as many Persistent objects.
However, in the case where a developer may need to retain a small chunk of memory from a pool for an indeterminate amount of time, it may be appropriate to create an un-pooled Buffer instance using Buffer.allocUnsafeSlow() then copy out the relevant bits. (2^31)-1). }}} is thrown. A zero-length Buffer will be created if a size less than or equal to 0 is specified.
The underlying memory for Buffer instances created in this way is not initialized. The contents of the newly created Buffer are unknown and may contain sensitive data. Use buf.fill(0) to initialize such Buffer instances to zeroes.
When using Buffer.allocUnsafe() to allocate new Buffer instances, allocations under 4KB are, by default, sliced from a single pre-allocated Buffer. This allows applications to avoid the garbage collection overhead of creating many individually allocated Buffers. This approach improves both performance and memory usage by eliminating the need to track and cleanup as many Persistent objects.
However, in the case where a developer may need to retain a small chunk of memory from a pool for an indeterminate amount of time, it may be appropriate to create an un-pooled Buffer instance using Buffer.allocUnsafeSlow() then copy out the relevant bits.
- size
the allocated size.
Buffer.allocUnsafeSlow(size)
Example: -
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
byteLength(string: Any, encoding: String = "utf8"): Int
Returns the actual byte length of a string.
Returns the actual byte length of a string. This is not the same as String.prototype.length since that returns the number of characters in a string.
- string
<String> | <Buffer> | <TypedArray> | <DataView> | <ArrayBuffer>
- encoding
the optional encoding (default "utf8")
Buffer.byteLength(string[, encoding])
Example: -
def
clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
def
compare(buf1: Buffer, buf2: Buffer): Int
Compares buf1 to buf2 typically for the purpose of sorting arrays of Buffers.
Compares buf1 to buf2 typically for the purpose of sorting arrays of Buffers. This is equivalent is calling buf1.compare(buf2).
-
def
concat(list: Array[Buffer]): Buffer
Returns a new Buffer which is the result of concatenating all the Buffers in the list together.
Returns a new Buffer which is the result of concatenating all the Buffers in the list together. If the list has no items, or if the totalLength is 0, then a new zero-length Buffer is returned. If totalLength is not provided, it is calculated from the Buffers in the list. This, however, adds an additional loop to the function, so it is faster to provide the length explicitly.
- list
the list of Buffer objects to concat
Buffer.concat(list[, totalLength])
Example: -
def
concat(list: Array[Buffer], totalLength: Int): Buffer
Returns a new Buffer which is the result of concatenating all the Buffers in the list together.
Returns a new Buffer which is the result of concatenating all the Buffers in the list together. If the list has no items, or if the totalLength is 0, then a new zero-length Buffer is returned. If totalLength is not provided, it is calculated from the Buffers in the list. This, however, adds an additional loop to the function, so it is faster to provide the length explicitly.
- list
the list of Buffer objects to concat
- totalLength
the optional total length
Buffer.concat(list[, totalLength])
Example: -
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
finalize(): Unit
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
def
from(str: String, encoding: String = js.native): Buffer
Creates a new Buffer containing the given JavaScript string str.
Creates a new Buffer containing the given JavaScript string str. If provided, the encoding parameter identifies the strings character encoding.
- str
the source string
- encoding
the given encoding
- returns
a new Buffer
-
def
from(array: Array[Int]): Buffer
Allocates a new Buffer using an array of octets.
Allocates a new Buffer using an array of octets.
Buffer.from(array)
Example: -
def
from(arrayBuffer: ArrayBuffer): Buffer
When passed a reference to the .buffer property of a TypedArray instance, the newly created Buffer will share the same allocated memory as the TypedArray.
When passed a reference to the .buffer property of a TypedArray instance, the newly created Buffer will share the same allocated memory as the TypedArray.
Buffer.from(arrayBuffer[, byteOffset[, length]])
Example: -
def
from(arrayBuffer: ArrayBuffer, byteOffset: Int): Buffer
When passed a reference to the .buffer property of a TypedArray instance, the newly created Buffer will share the same allocated memory as the TypedArray.
When passed a reference to the .buffer property of a TypedArray instance, the newly created Buffer will share the same allocated memory as the TypedArray.
Buffer.from(arrayBuffer[, byteOffset[, length]])
Example: -
def
from(arrayBuffer: ArrayBuffer, byteOffset: Int, length: Int): Buffer
When passed a reference to the .buffer property of a TypedArray instance, the newly created Buffer will share the same allocated memory as the TypedArray.
When passed a reference to the .buffer property of a TypedArray instance, the newly created Buffer will share the same allocated memory as the TypedArray.
Buffer.from(arrayBuffer[, byteOffset[, length]])
Example: -
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
-
def
hasOwnProperty(v: String): Boolean
- Definition Classes
- Object
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
-
def
isBuffer(obj: Any): Boolean
Returns true if obj is a Buffer, false otherwise.
Returns true if obj is a Buffer, false otherwise.
- obj
the given object
- returns
true if obj is a Buffer, false otherwise.
-
def
isEncoding(encoding: String): Boolean
Returns true if encoding contains a supported character encoding, or false otherwise.
Returns true if encoding contains a supported character encoding, or false otherwise.
- encoding
A character encoding name to check
- returns
true if encoding contains a supported character encoding, or false otherwise.
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
def
isPrototypeOf(v: Object): Boolean
- Definition Classes
- Object
-
val
kMaxLength: Int
On 32-bit architectures, this value is (230)-1 (~1GB). On 64-bit architectures, this value is (231)-1 (~2GB).F Note that this is a property on the buffer module returned by require('buffer'), not on the Buffer global or a Buffer instance.
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
-
var
poolSize: Int
This is the number of bytes used to determine the size of pre-allocated, internal Buffer instances used for pooling.
This is the number of bytes used to determine the size of pre-allocated, internal Buffer instances used for pooling. This value may be modified.
-
def
propertyIsEnumerable(v: String): Boolean
- Definition Classes
- Object
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toLocaleString(): String
- Definition Classes
- Object
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
def
transcode(source: Buffer, fromEnc: String, toEnc: String): Buffer
Re-encodes the given Buffer instance from one character encoding to another.
Re-encodes the given Buffer instance from one character encoding to another. Returns a new Buffer instance.
Throws if the fromEnc or toEnc specify invalid character encodings or if conversion from fromEnc to toEnc is not permitted.
The transcoding process will use substitution characters if a given byte sequence cannot be adequately represented in the target encoding.
- source
A Buffer instance
- fromEnc
The current encoding
- toEnc
To target encoding
- returns
a new Buffer instance.
-
def
valueOf(): Any
- Definition Classes
- Object
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )