2022-05-30 14:01:36 +02:00
|
|
|
const Primitives =
|
|
|
|
require('next/dist/compiled/@edge-runtime/primitives').default
|
2022-04-18 16:24:06 +02:00
|
|
|
|
2022-05-30 14:01:36 +02:00
|
|
|
const OriginWritableStreamWrite =
|
|
|
|
Primitives.WritableStreamDefaultWriter.prototype.write
|
2022-04-18 16:24:06 +02:00
|
|
|
|
|
|
|
// Override writable stream write method to validate chunk type.
|
|
|
|
// Currently CF workers only allow to write the encoded chunk in Uint8Array format.
|
2022-05-30 14:01:36 +02:00
|
|
|
Primitives.WritableStreamDefaultWriter.prototype.write = function (chunk) {
|
2022-04-18 16:24:06 +02:00
|
|
|
if (!(chunk instanceof Uint8Array)) {
|
|
|
|
throw new Error('Writing non-Uint8Array chunks in a stream is not allowed.')
|
|
|
|
}
|
|
|
|
return OriginWritableStreamWrite.call(this, chunk)
|
|
|
|
}
|
|
|
|
|
2022-05-30 14:01:36 +02:00
|
|
|
global.ReadableStream = Primitives.ReadableStream
|
|
|
|
global.TransformStream = Primitives.TransformStream
|