diff options
Diffstat (limited to 'std/mime/multipart.ts')
-rw-r--r-- | std/mime/multipart.ts | 36 |
1 files changed, 15 insertions, 21 deletions
diff --git a/std/mime/multipart.ts b/std/mime/multipart.ts index 73a6544b5..42be47895 100644 --- a/std/mime/multipart.ts +++ b/std/mime/multipart.ts @@ -1,10 +1,4 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. - -const { Buffer, copy, remove } = Deno; -const { min, max } = Math; -type Closer = Deno.Closer; -type Reader = Deno.Reader; -type Writer = Deno.Writer; import { equal, findIndex, findLastIndex, hasPrefix } from "../bytes/mod.ts"; import { copyN } from "../io/ioutil.ts"; import { MultiReader } from "../io/readers.ts"; @@ -150,7 +144,7 @@ export function scanUntilBoundary( return buf.length; } -class PartReader implements Reader, Closer { +class PartReader implements Deno.Reader, Deno.Closer { n: number | null = 0; total = 0; @@ -163,7 +157,7 @@ class PartReader implements Reader, Closer { // or we find a reason to stop (boundary or EOF). let peekLength = 1; while (this.n === 0) { - peekLength = max(peekLength, br.buffered()); + peekLength = Math.max(peekLength, br.buffered()); const peekBuf = await br.peek(peekLength); if (peekBuf === null) { throw new Deno.errors.UnexpectedEof(); @@ -187,7 +181,7 @@ class PartReader implements Reader, Closer { return null; } - const nread = min(p.length, this.n); + const nread = Math.min(p.length, this.n); const buf = p.subarray(0, nread); const r = await br.readFull(buf); assert(r === buf); @@ -272,7 +266,7 @@ export class MultipartReader { readonly dashBoundary = encoder.encode(`--${this.boundary}`); readonly bufReader: BufReader; - constructor(reader: Reader, private boundary: string) { + constructor(reader: Deno.Reader, private boundary: string) { this.bufReader = new BufReader(reader); } @@ -287,7 +281,7 @@ export class MultipartReader { const fileMap = new Map<string, FormFile | FormFile[]>(); const valueMap = new Map<string, string>(); let maxValueBytes = maxMemory + (10 << 20); - const buf = new Buffer(new Uint8Array(maxValueBytes)); + const buf = new Deno.Buffer(new Uint8Array(maxValueBytes)); for (;;) { const p = await this.nextPart(); if (p === null) { @@ -321,7 +315,7 @@ export class MultipartReader { postfix: ext, }); try { - const size = await copy(new MultiReader(buf, p), file); + const size = await Deno.copy(new MultiReader(buf, p), file); file.close(); formFile = { @@ -331,7 +325,7 @@ export class MultipartReader { size, }; } catch (e) { - await remove(filepath); + await Deno.remove(filepath); throw e; } } else { @@ -465,13 +459,13 @@ function multipatFormData( }; } -class PartWriter implements Writer { +class PartWriter implements Deno.Writer { closed = false; private readonly partHeader: string; private headersWritten = false; constructor( - private writer: Writer, + private writer: Deno.Writer, readonly boundary: string, public headers: Headers, isFirstBoundary: boolean @@ -531,7 +525,7 @@ export class MultipartWriter { private bufWriter: BufWriter; private isClosed = false; - constructor(private readonly writer: Writer, boundary?: string) { + constructor(private readonly writer: Deno.Writer, boundary?: string) { if (boundary !== void 0) { this._boundary = checkBoundary(boundary); } else { @@ -544,7 +538,7 @@ export class MultipartWriter { return `multipart/form-data; boundary=${this.boundary}`; } - private createPart(headers: Headers): Writer { + private createPart(headers: Headers): Deno.Writer { if (this.isClosed) { throw new Error("multipart: writer is closed"); } @@ -561,7 +555,7 @@ export class MultipartWriter { return part; } - createFormFile(field: string, filename: string): Writer { + createFormFile(field: string, filename: string): Deno.Writer { const h = new Headers(); h.set( "Content-Disposition", @@ -571,7 +565,7 @@ export class MultipartWriter { return this.createPart(h); } - createFormField(field: string): Writer { + createFormField(field: string): Deno.Writer { const h = new Headers(); h.set("Content-Disposition", `form-data; name="${field}"`); h.set("Content-Type", "application/octet-stream"); @@ -586,10 +580,10 @@ export class MultipartWriter { async writeFile( field: string, filename: string, - file: Reader + file: Deno.Reader ): Promise<void> { const f = await this.createFormFile(field, filename); - await copy(file, f); + await Deno.copy(file, f); } private flush(): Promise<void> { |