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

Method readBytes

packages/effect/src/http/HttpServerRequest.ts:831–852  ·  view source on GitHub ↗
(maxBytes: number | undefined)

Source from the content-addressed store, hash-verified

829 }
830
831 private readBytes(maxBytes: number | undefined): Effect.Effect<Uint8Array, HttpServerError> {
832 const body = this.source.body
833 switch (body._tag) {
834 case "Empty": {
835 return Effect.succeed(new Uint8Array(0))
836 }
837 case "Uint8Array": {
838 return maxBytes !== undefined && body.body.byteLength > maxBytes
839 ? Effect.fail(bodyTooLargeError(this, new BodyTooLargeError(maxBytes)))
840 : Effect.succeed(body.body)
841 }
842 case "FormData": {
843 return bytesFromWeb(this, () => new Response(body.formData), maxBytes)
844 }
845 case "Stream": {
846 return Stream.mkUint8Array(maxBytes === undefined ? this.stream : limitStream(this, this.stream, maxBytes))
847 }
848 case "Raw": {
849 return rawBodyBytes(this, body.body, maxBytes)
850 }
851 }
852 }
853
854 get text(): Effect.Effect<string, HttpServerError> {
855 return Effect.map(this.bytes, (bytes) => textDecoder.decode(bytes))

Callers 1

bytesMethod · 0.95

Calls 6

bodyTooLargeErrorFunction · 0.85
bytesFromWebFunction · 0.85
limitStreamFunction · 0.85
rawBodyBytesFunction · 0.85
failMethod · 0.65
succeedMethod · 0.45

Tested by

no test coverage detected