mirror of
https://github.com/denoland/deno.git
synced 2025-01-21 21:50:00 -05:00
refactor(cli/web): use isTypedArray method (#6369)
This commit is contained in:
parent
70147ee564
commit
36ad5e4402
1 changed files with 7 additions and 23 deletions
|
@ -3,7 +3,11 @@ import * as encoding from "./text_encoding.ts";
|
|||
import * as domTypes from "./dom_types.d.ts";
|
||||
import { ReadableStreamImpl } from "./streams/readable_stream.ts";
|
||||
import { isReadableStreamDisturbed } from "./streams/internals.ts";
|
||||
import { getHeaderValueParams, hasHeaderValueOf } from "./util.ts";
|
||||
import {
|
||||
getHeaderValueParams,
|
||||
hasHeaderValueOf,
|
||||
isTypedArray,
|
||||
} from "./util.ts";
|
||||
import { MultipartParser } from "./fetch/multipart.ts";
|
||||
|
||||
// only namespace imports work for now, plucking out what we need
|
||||
|
@ -11,17 +15,7 @@ const { TextEncoder, TextDecoder } = encoding;
|
|||
const DenoBlob = blob.DenoBlob;
|
||||
|
||||
function validateBodyType(owner: Body, bodySource: BodyInit | null): boolean {
|
||||
if (
|
||||
bodySource instanceof Int8Array ||
|
||||
bodySource instanceof Int16Array ||
|
||||
bodySource instanceof Int32Array ||
|
||||
bodySource instanceof Uint8Array ||
|
||||
bodySource instanceof Uint16Array ||
|
||||
bodySource instanceof Uint32Array ||
|
||||
bodySource instanceof Uint8ClampedArray ||
|
||||
bodySource instanceof Float32Array ||
|
||||
bodySource instanceof Float64Array
|
||||
) {
|
||||
if (isTypedArray(bodySource)) {
|
||||
return true;
|
||||
} else if (bodySource instanceof ArrayBuffer) {
|
||||
return true;
|
||||
|
@ -188,17 +182,7 @@ export class Body implements domTypes.Body {
|
|||
}
|
||||
|
||||
public arrayBuffer(): Promise<ArrayBuffer> {
|
||||
if (
|
||||
this._bodySource instanceof Int8Array ||
|
||||
this._bodySource instanceof Int16Array ||
|
||||
this._bodySource instanceof Int32Array ||
|
||||
this._bodySource instanceof Uint8Array ||
|
||||
this._bodySource instanceof Uint16Array ||
|
||||
this._bodySource instanceof Uint32Array ||
|
||||
this._bodySource instanceof Uint8ClampedArray ||
|
||||
this._bodySource instanceof Float32Array ||
|
||||
this._bodySource instanceof Float64Array
|
||||
) {
|
||||
if (isTypedArray(this._bodySource)) {
|
||||
return Promise.resolve(this._bodySource.buffer as ArrayBuffer);
|
||||
} else if (this._bodySource instanceof ArrayBuffer) {
|
||||
return Promise.resolve(this._bodySource);
|
||||
|
|
Loading…
Add table
Reference in a new issue