Primate Logo Primate
Guides Responses

Stream binary data

Serve binary data like files or images. Use the binary response.

Serve file

Read and return binary data.

// routes/file.ts
import fs from "@rcompat/fs";
import response from "primate/response";
import route from "primate/route";

const file = fs.ref("path/to/file.pdf");

export default route({
  get() {
    return response.binary(file);
  },
});

Serve stream

Response back with the uploaded steam -- Blobs are automatically streamed.

// routes/backstream.ts
import route from "primate/route";

export default route({
  post(request) {
    return request.body.binary();
  },
});