blobReadingMethods
Prefer direct Blob reading methods over wrapping in Response for simpler code.
✅ This rule is included in the nodestylisticandstylisticStrictpresets.
Direct Blob methods are simpler and more direct than wrapping the Blob in a Response object. The Response wrapper adds unnecessary complexity when the Blob already provides the needed methods.
Examples
Section titled “Examples”const const text: string
text = await new var Response: new (body?: BodyInit | null, init?: ResponseInit) => Response
The Response interface of the Fetch API represents the response to a request.
Response(const blob: Blob
blob).Body.text(): Promise<string>
text();
const const arrayBuffer: ArrayBuffer
arrayBuffer = await new var Response: new (body?: BodyInit | null, init?: ResponseInit) => Response
The Response interface of the Fetch API represents the response to a request.
Response(const blob: Blob
blob).Body.arrayBuffer(): Promise<ArrayBuffer>
arrayBuffer();
const const bytes: Uint8Array<ArrayBuffer>
bytes = await new var Response: new (body?: BodyInit | null, init?: ResponseInit) => Response
The Response interface of the Fetch API represents the response to a request.
Response(const blob: Blob
blob).Body.bytes(): Promise<Uint8Array<ArrayBuffer>>
bytes();const const text: string
text = await const blob: Blob
blob.Blob.text(): Promise<string>
The text() method of the string containing the contents of the blob, interpreted as UTF-8.
text();
const const arrayBuffer: ArrayBuffer
arrayBuffer = await const blob: Blob
blob.Blob.arrayBuffer(): Promise<ArrayBuffer>
The arrayBuffer() method of the Blob interface returns a Promise that resolves with the contents of the blob as binary data contained in an ArrayBuffer.
arrayBuffer();
const const bytes: Uint8Array<ArrayBuffer>
bytes = await const blob: Blob
blob.Blob.bytes(): Promise<Uint8Array<ArrayBuffer>>
The bytes() method of the Blob interface returns a Promise that resolves with a Uint8Array containing the contents of the blob as an array of bytes.
bytes();Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”If you need to use Response-specific functionality while reading the Blob data, you might choose not to enable this rule.