mirror of
https://github.com/denoland/deno.git
synced 2025-02-08 07:16:56 -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 * as domTypes from "./dom_types.d.ts";
|
||||||
import { ReadableStreamImpl } from "./streams/readable_stream.ts";
|
import { ReadableStreamImpl } from "./streams/readable_stream.ts";
|
||||||
import { isReadableStreamDisturbed } from "./streams/internals.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";
|
import { MultipartParser } from "./fetch/multipart.ts";
|
||||||
|
|
||||||
// only namespace imports work for now, plucking out what we need
|
// only namespace imports work for now, plucking out what we need
|
||||||
|
@ -11,17 +15,7 @@ const { TextEncoder, TextDecoder } = encoding;
|
||||||
const DenoBlob = blob.DenoBlob;
|
const DenoBlob = blob.DenoBlob;
|
||||||
|
|
||||||
function validateBodyType(owner: Body, bodySource: BodyInit | null): boolean {
|
function validateBodyType(owner: Body, bodySource: BodyInit | null): boolean {
|
||||||
if (
|
if (isTypedArray(bodySource)) {
|
||||||
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
|
|
||||||
) {
|
|
||||||
return true;
|
return true;
|
||||||
} else if (bodySource instanceof ArrayBuffer) {
|
} else if (bodySource instanceof ArrayBuffer) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -188,17 +182,7 @@ export class Body implements domTypes.Body {
|
||||||
}
|
}
|
||||||
|
|
||||||
public arrayBuffer(): Promise<ArrayBuffer> {
|
public arrayBuffer(): Promise<ArrayBuffer> {
|
||||||
if (
|
if (isTypedArray(this._bodySource)) {
|
||||||
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
|
|
||||||
) {
|
|
||||||
return Promise.resolve(this._bodySource.buffer as ArrayBuffer);
|
return Promise.resolve(this._bodySource.buffer as ArrayBuffer);
|
||||||
} else if (this._bodySource instanceof ArrayBuffer) {
|
} else if (this._bodySource instanceof ArrayBuffer) {
|
||||||
return Promise.resolve(this._bodySource);
|
return Promise.resolve(this._bodySource);
|
||||||
|
|
Loading…
Add table
Reference in a new issue