@remotion/streaming
Advanced tools
Comparing version 4.0.183 to 4.0.184
@@ -6,3 +6,2 @@ "use strict"; | ||
exports.streamingKey = 'remotion_buffer:'; | ||
const magicWordStr = 'remotion_buffer:'; | ||
// @ts-expect-error | ||
@@ -13,5 +12,5 @@ globalThis._dumpUnreleasedBuffers = new stream_1.EventEmitter(); | ||
const makeStreamer = (onMessage) => { | ||
const separator = new Uint8Array(magicWordStr.length); | ||
for (let i = 0; i < magicWordStr.length; i++) { | ||
separator[i] = magicWordStr.charCodeAt(i); | ||
const separator = new Uint8Array(exports.streamingKey.length); | ||
for (let i = 0; i < exports.streamingKey.length; i++) { | ||
separator[i] = exports.streamingKey.charCodeAt(i); | ||
} | ||
@@ -21,8 +20,22 @@ let unprocessedBuffers = []; | ||
let missingData = null; | ||
const processInput = () => { | ||
let separatorIndex = outputBuffer.indexOf(separator[0]); // Start checking for the first byte of the separator | ||
if (separatorIndex === -1 || | ||
outputBuffer | ||
const findSeparatorIndex = () => { | ||
let searchIndex = 0; | ||
// eslint-disable-next-line no-constant-condition | ||
while (true) { | ||
const separatorIndex = outputBuffer.indexOf(separator[0], searchIndex); // Start checking for the first byte of the separator | ||
if (separatorIndex === -1) { | ||
return -1; | ||
} | ||
if (outputBuffer | ||
.subarray(separatorIndex, separatorIndex + separator.length) | ||
.toString() !== separator.toString()) { | ||
searchIndex = separatorIndex + 1; | ||
continue; | ||
} | ||
return separatorIndex; | ||
} | ||
}; | ||
const processInput = () => { | ||
let separatorIndex = findSeparatorIndex(); // Start checking for the first byte of the separator | ||
if (separatorIndex === -1) { | ||
return; | ||
@@ -92,18 +105,17 @@ } | ||
unprocessedBuffers.push(data); | ||
const separatorIndex = data.indexOf(separator[0]); | ||
if (separatorIndex === -1) { | ||
if (missingData) { | ||
missingData.dataMissing -= data.length; | ||
} | ||
if (!missingData || missingData.dataMissing > 0) { | ||
return; | ||
} | ||
if (missingData) { | ||
missingData.dataMissing -= data.length; | ||
} | ||
unprocessedBuffers.unshift(outputBuffer); | ||
outputBuffer = new Uint8Array(unprocessedBuffers.reduce((acc, val) => acc + val.length, 0)); | ||
let offset = 0; | ||
if (missingData && missingData.dataMissing > 0) { | ||
return; | ||
} | ||
const newBuffer = new Uint8Array(outputBuffer.length + | ||
unprocessedBuffers.reduce((acc, val) => acc + val.length, 0)); | ||
newBuffer.set(outputBuffer, 0); | ||
let offset = outputBuffer.length; | ||
for (const buf of unprocessedBuffers) { | ||
outputBuffer.set(buf, offset); | ||
newBuffer.set(buf, offset); | ||
offset += buf.length; | ||
} | ||
outputBuffer = newBuffer; | ||
unprocessedBuffers = []; | ||
@@ -126,3 +138,3 @@ processInput(); | ||
const nonceArr = new TextEncoder().encode(nonce); | ||
const magicWordArr = new TextEncoder().encode(magicWordStr); | ||
const magicWordArr = new TextEncoder().encode(exports.streamingKey); | ||
const separatorArr = new TextEncoder().encode(':'); | ||
@@ -129,0 +141,0 @@ const bodyLengthArr = new TextEncoder().encode(body.length.toString()); |
@@ -6,3 +6,3 @@ { | ||
"name": "@remotion/streaming", | ||
"version": "4.0.183", | ||
"version": "4.0.184", | ||
"description": "Utilities for streaming data between programs", | ||
@@ -9,0 +9,0 @@ "main": "dist", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
50857
227