MCPcopy Create free account
hub / github.com/Effect-TS/effect / limitStream

Function limitStream

packages/effect/src/http/HttpServerRequest.ts:1010–1023  ·  view source on GitHub ↗
(
  request: HttpServerRequest,
  stream: Stream.Stream<Uint8Array, HttpServerError>,
  maxBytes: number
)

Source from the content-addressed store, hash-verified

1008 })
1009
1010const limitStream = (
1011 request: HttpServerRequest,
1012 stream: Stream.Stream<Uint8Array, HttpServerError>,
1013 maxBytes: number
1014): Stream.Stream<Uint8Array, HttpServerError> =>
1015 Stream.suspend(() => {
1016 let bytes = 0
1017 return Stream.mapEffect(stream, (chunk) => {
1018 bytes += chunk.byteLength
1019 return bytes > maxBytes
1020 ? Effect.fail(bodyTooLargeError(request, new BodyTooLargeError(maxBytes)))
1021 : Effect.succeed(chunk)
1022 })
1023 })
1024
1025const bodyTooLargeError = (request: HttpServerRequest, cause: BodyTooLargeError) =>
1026 new HttpServerError({ reason: new RequestParseError({ request, reason: "BodyTooLarge", cause }) })

Callers 1

readBytesMethod · 0.85

Calls 3

bodyTooLargeErrorFunction · 0.85
failMethod · 0.65
succeedMethod · 0.45

Tested by

no test coverage detected