mirror of
https://github.com/koush/scrypted.git
synced 2026-04-25 09:20:24 +01:00
server: sketchy check to determine if buffer is pool buffer
This commit is contained in:
@@ -12,9 +12,14 @@ class BufferTransfer implements RpcSerializer {
|
||||
if (!serializationContext)
|
||||
return this.bufferSerializer.serialize(value);
|
||||
|
||||
// must create a copy. Buffers as allocated by node are not transferable.
|
||||
const ab = value.buffer.slice(value.byteOffset, value.byteOffset + value.byteLength);
|
||||
value = Buffer.from(ab);
|
||||
// node may used pooled buffers for Buffer.allocUnsafe, Buffer.from, and other calls.
|
||||
// these buffers will be smaller than Buffer.poolSize.
|
||||
// In these instances, do not transfer the buffer, as it may not be transferible.
|
||||
// create a copy so it can be safely transfered.
|
||||
if (value.buffer.byteLength <= Buffer.poolSize) {
|
||||
const ab = value.buffer.slice(value.byteOffset, value.byteOffset + value.byteLength);
|
||||
value = Buffer.from(ab);
|
||||
}
|
||||
|
||||
serializationContext.transferList ||= [];
|
||||
const transferList: worker_threads.TransferListItem[] = serializationContext.transferList;
|
||||
|
||||
Reference in New Issue
Block a user