R2 `Provided readable stream must have a known length` from workers

I would like to stream a file to R2 that's being created by iterating over items in memory and JSON-stringifying them (reduce memory consumption by not double-buffering them in memory)
const { readable, writable } = new TransformStream<Uint8Array, Uint8Array>()
        const writer = writable.getWriter()

        // start streaming the records to the file
        const writePromise = this.env.StreamData.put(segmentName, readable)


However I'm getting the error:
stderr | tests/index.test.ts > Worker > durable object > should create a new stream and produce messages
✘ [ERROR] Uncaught (in promise) TypeError: Provided readable stream must have a known length (request/response body or readable half of FixedLengthStream)

      at async Promise.all (index 1)
      at async StreamCoordinator.writePendingMessagesToLogSegment (file:///Users/dangoodman/code/DurableStreams/.wrangler/tmp/dev-qAfkZE/index.js:2058:5)
      at async StreamCoordinator.flushPendingMessages (file:///Users/dangoodman/code/DurableStreams/.wrangler/tmp/dev-qAfkZE/index.js:2034:5)
      at async StreamCoordinator.alarm (file:///Users/dangoodman/code/DurableStreams/.wrangler/tmp/dev-qAfkZE/index.js:2014:5)


Is there a way I can stream data to R2 without knowing the exact content length ahead of time?
Was this page helpful?