diff --git a/_readers_test.ts b/_readers_test.ts index d3fbff9..ef27b27 100644 --- a/_readers_test.ts +++ b/_readers_test.ts @@ -3,6 +3,7 @@ import { streamReader } from "./_readers.ts"; import { assertEquals } from "./vendor/https/deno.land/std/testing/asserts.ts"; import { group } from "./_test_util.ts"; import { decode, encode } from "./_util.ts"; +import { Buffer } from "./vendor/https/deno.land/std/io/buffer.ts"; group("streamReader", ({ test }) => { test("basic", async () => { @@ -16,7 +17,7 @@ group("streamReader", ({ test }) => { }); const sr = streamReader(stream); const buf = new Uint8Array(3); - const dest = new Deno.Buffer(); + const dest = new Buffer(); let result: null | number = 0; while ((result = await sr.read(buf)) !== null) { await dest.write(buf.subarray(0, result)); diff --git a/body_parser.ts b/body_parser.ts index 5e8571a..f33c152 100644 --- a/body_parser.ts +++ b/body_parser.ts @@ -4,6 +4,7 @@ import { MultipartReader, } from "./vendor/https/deno.land/std/mime/multipart.ts"; import { decode } from "./_util.ts"; +import { Buffer } from "./vendor/https/deno.land/std/io/buffer.ts"; import Reader = Deno.Reader; export interface BodyParser { @@ -18,7 +19,7 @@ export function createBodyParser(holder: { readonly contentType: string; readonly maxMemory?: number; }): BodyParser { - let bodyBuf: Deno.Buffer | undefined; + let bodyBuf: Buffer | undefined; let formBody: MultipartFormData | undefined; let textBody: string | undefined; let jsonBody: any | undefined; @@ -67,7 +68,7 @@ export function createBodyParser(holder: { } else if (bodyBuf) { return (jsonBody = JSON.parse(decode(bodyBuf.bytes()))); } - bodyBuf = new Deno.Buffer(); + bodyBuf = new Buffer(); await Deno.copy(holder.reader, bodyBuf); return JSON.parse(decode(bodyBuf.bytes())); } @@ -78,7 +79,7 @@ export function createBodyParser(holder: { } else if (bodyBuf) { return (textBody = decode(bodyBuf.bytes())); } - bodyBuf = new Deno.Buffer(); + bodyBuf = new Buffer(); await Deno.copy(holder.reader, bodyBuf); return (textBody = decode(bodyBuf.bytes())); } @@ -87,7 +88,7 @@ export function createBodyParser(holder: { if (bodyBuf) { return bodyBuf.bytes(); } - bodyBuf = new Deno.Buffer(); + bodyBuf = new Buffer(); await Deno.copy(holder.reader, bodyBuf); return bodyBuf.bytes(); } @@ -138,7 +139,7 @@ export async function parseUrlEncodedForm(req: { ) { throw new Error("is not form urlencoded request"); } - const buf = new Deno.Buffer(); + const buf = new Buffer(); await Deno.copy(req.body, buf); const params = new URLSearchParams(decodeURIComponent(decode(buf.bytes()))); function* entries() { diff --git a/body_parser_test.ts b/body_parser_test.ts index 22da3bf..e73adb4 100644 --- a/body_parser_test.ts +++ b/body_parser_test.ts @@ -9,7 +9,7 @@ import { } from "./vendor/https/deno.land/std/testing/asserts.ts"; import { createBodyParser, parserMultipartRequest } from "./body_parser.ts"; import { exists as fsExists } from "./vendor/https/deno.land/std/fs/exists.ts"; -import Buffer = Deno.Buffer; +import { Buffer } from "./vendor/https/deno.land/std/io/buffer.ts"; import { group } from "./_test_util.ts"; import { StringReader } from "./vendor/https/deno.land/std/io/readers.ts"; @@ -117,7 +117,7 @@ group("bodyParser", ({ test }) => { ); }); test("arrayBuffer()", async () => { - const bin = new Deno.Buffer(new Uint8Array([0, 1, 2, 3])); + const bin = new Buffer(new Uint8Array([0, 1, 2, 3])); const br = createBodyParser( { reader: bin, contentType: "application/octet-stream" }, ); diff --git a/modules-lock.json b/modules-lock.json index 793964c..2d68d73 100644 --- a/modules-lock.json +++ b/modules-lock.json @@ -11,6 +11,7 @@ "/io/bufio.ts", "/io/readers.ts", "/io/writers.ts", + "/io/buffer.ts", "/http/_io.ts", "/http/http_status.ts", "/flags/mod.ts", diff --git a/modules.json b/modules.json index 793964c..2d68d73 100755 --- a/modules.json +++ b/modules.json @@ -11,6 +11,7 @@ "/io/bufio.ts", "/io/readers.ts", "/io/writers.ts", + "/io/buffer.ts", "/http/_io.ts", "/http/http_status.ts", "/flags/mod.ts", diff --git a/responder_test.ts b/responder_test.ts index 8d07680..a5fbb72 100644 --- a/responder_test.ts +++ b/responder_test.ts @@ -8,13 +8,14 @@ import { import { StringReader } from "./vendor/https/deno.land/std/io/readers.ts"; import { readResponse, writeResponse } from "./serveio.ts"; import { group } from "./_test_util.ts"; +import { Buffer } from "./vendor/https/deno.land/std/io/buffer.ts"; group("responder", (t) => { function _createResponder(w: Deno.Writer) { return createResponder((resp) => writeResponse(w, resp)); } t.test("basic", async function () { - const w = new Deno.Buffer(); + const w = new Buffer(); const res = _createResponder(w); assert(!res.isResponded()); await res.respond({ @@ -32,7 +33,7 @@ group("responder", (t) => { }); t.test("respond() should throw if already responded", async function () { - const w = new Deno.Buffer(); + const w = new Buffer(); const res = _createResponder(w); await res.respond({ status: 200, @@ -50,7 +51,7 @@ group("responder", (t) => { }); t.test("sendFile() basic", async function () { - const w = new Deno.Buffer(); + const w = new Buffer(); const res = _createResponder(w); await res.sendFile("./fixtures/sample.txt"); const resp = await readResponse(w); @@ -60,7 +61,7 @@ group("responder", (t) => { }); t.test("sendFile() should throw if file not found", async () => { - const w = new Deno.Buffer(); + const w = new Buffer(); const res = _createResponder(w); await assertThrowsAsync( () => res.sendFile("./fixtures/not-found"), @@ -69,7 +70,7 @@ group("responder", (t) => { }); t.test("sendFile() with attachment", async () => { - const w = new Deno.Buffer(); + const w = new Buffer(); const res = _createResponder(w); await res.sendFile("./fixtures/sample.txt", { contentDisposition: "inline", @@ -81,7 +82,7 @@ group("responder", (t) => { }); t.test("sendFile() with attachment", async () => { - const w = new Deno.Buffer(); + const w = new Buffer(); const res = _createResponder(w); await res.sendFile("./fixtures/sample.txt", { contentDisposition: "attachment", @@ -96,7 +97,7 @@ group("responder", (t) => { }); t.test("redirect() should set Location header", async () => { - const w = new Deno.Buffer(); + const w = new Buffer(); const res = _createResponder(w); await res.redirect("/index.html"); const { status, headers } = await readResponse(w); @@ -105,7 +106,7 @@ group("responder", (t) => { }); t.test("redirect() should use partial body for response", async () => { - const w = new Deno.Buffer(); + const w = new Buffer(); const res = _createResponder(w); await res.redirect("/", { status: 303, @@ -119,7 +120,7 @@ group("responder", (t) => { }); t.test("resirect() should throw error if status code is not in 300~399", async () => { - const w = new Deno.Buffer(); + const w = new Buffer(); const res = _createResponder(w); await assertThrowsAsync( async () => { @@ -131,7 +132,7 @@ group("responder", (t) => { }); t.test("markResponded()", async () => { - const w = new Deno.Buffer(); + const w = new Buffer(); const res = _createResponder(w); res.markAsResponded(200); assertEquals(res.isResponded(), true); diff --git a/serveio.ts b/serveio.ts index 8ddd858..6e90274 100644 --- a/serveio.ts +++ b/serveio.ts @@ -1,5 +1,6 @@ // Copyright 2019-2020 Yusuke Sakurai. All rights reserved. MIT license. import { BufReader, BufWriter } from "./vendor/https/deno.land/std/io/bufio.ts"; +import { Buffer } from "./vendor/https/deno.land/std/io/buffer.ts"; import { TextProtoReader } from "./vendor/https/deno.land/std/textproto/mod.ts"; import { closableBodyReader, streamReader, timeoutReader } from "./_readers.ts"; import { encode, promiseInterrupter } from "./_util.ts"; @@ -19,7 +20,6 @@ import { } from "./server.ts"; import Reader = Deno.Reader; import Writer = Deno.Writer; -import Buffer = Deno.Buffer; import { toIMF } from "./vendor/https/deno.land/std/datetime/mod.ts"; import { parseCookie } from "./cookie.ts"; import { diff --git a/serveio_test.ts b/serveio_test.ts index cabc0c4..5f5f98c 100644 --- a/serveio_test.ts +++ b/serveio_test.ts @@ -12,7 +12,7 @@ import { import { assertEquals } from "./vendor/https/deno.land/std/testing/asserts.ts"; import { StringReader } from "./vendor/https/deno.land/std/io/readers.ts"; import { encode } from "./_util.ts"; -import Buffer = Deno.Buffer; +import { Buffer } from "./vendor/https/deno.land/std/io/buffer.ts"; import { ServerResponse } from "./server.ts"; import { group } from "./_test_util.ts"; import { noopReader } from "./_readers.ts"; diff --git a/server_test.ts b/server_test.ts index 20b2345..0520569 100644 --- a/server_test.ts +++ b/server_test.ts @@ -13,7 +13,7 @@ import { createAgent } from "./agent.ts"; import { readResponse, writeRequest } from "./serveio.ts"; import { BufReader } from "./vendor/https/deno.land/std/io/bufio.ts"; import { deferred, delay } from "./vendor/https/deno.land/std/async/mod.ts"; -import Buffer = Deno.Buffer; +import { Buffer } from "./vendor/https/deno.land/std/io/buffer.ts"; import { group } from "./_test_util.ts"; let port = 8880; diff --git a/site/public/example/comparison/body/std_http.ts b/site/public/example/comparison/body/std_http.ts index 029963c..b3cb33e 100644 --- a/site/public/example/comparison/body/std_http.ts +++ b/site/public/example/comparison/body/std_http.ts @@ -1,4 +1,5 @@ import { serve } from "https://deno.land/std/http/mod.ts"; +import { Buffer } from "https://deno.land/std/io/buffer.ts"; const server = serve({ port: 8888 }); for await (const req of server) { @@ -6,7 +7,7 @@ for await (const req of server) { req.method === "POST" && req.url === "/post" ) { - const buf = new Deno.Buffer(); + const buf = new Buffer(); await Deno.copy(req.body, buf); const decoder = new TextDecoder(); const str = decoder.decode(buf.bytes()); diff --git a/testing.ts b/testing.ts index 23d1427..d918f6b 100644 --- a/testing.ts +++ b/testing.ts @@ -1,5 +1,6 @@ // Copyright 2019-2020 Yusuke Sakurai. All rights reserved. MIT license. import { BufReader, BufWriter } from "./vendor/https/deno.land/std/io/bufio.ts"; +import { Buffer } from "./vendor/https/deno.land/std/io/buffer.ts"; import { BodyReader, HttpBody, @@ -50,7 +51,7 @@ export function createRecorder(opts?: { return 0; }, }; - const buf = new Deno.Buffer(); + const buf = new Buffer(); const bufReader = new BufReader(buf); const bufWriter = new BufWriter(buf); let br: BodyReader; diff --git a/vendor/https/deno.land/std/io/buffer.ts b/vendor/https/deno.land/std/io/buffer.ts new file mode 100644 index 0000000..7dbf62b --- /dev/null +++ b/vendor/https/deno.land/std/io/buffer.ts @@ -0,0 +1 @@ +export * from "https://deno.land/std@0.92.0/io/buffer.ts";