SIGN IN SIGN UP

fix(studio-server): stream preview media byte ranges instead of reading the whole file (#3745)

The Studio preview asset route answered every Range request by reading the
entire file into memory with readFileSync and slicing the window out of the
buffer. A browser refills a playing <video> or <audio> with a fresh Range
request every few hundred milliseconds and issues one per seek, so a source
of a few hundred MB cost a full synchronous read per refill and per scrub
step. The read also blocked the event loop, so the voice track, saves and
the file-change stream all waited behind it. Sources over 2 GiB could not
be served at all, because readFileSync refuses them.

Stream only the requested window with createReadStream, take the size from
stat instead of the buffer, and answer 416 for a range that starts past the
end. Text assets keep the in-memory utf-8 round trip. The sibling static
project server already did this.
M
Miguel Ángel committed
8825def610fed12985329e495993d47a3943df3e
Parent: 0d5d3f3
Committed by GitHub <noreply@github.com> on 9/7/2026, 2:55:54 PM