diff options
| author | Kevin (Kun) "Kassimo" Qian <kevinkassimo@gmail.com> | 2018-12-17 23:14:22 -0500 |
|---|---|---|
| committer | Ryan Dahl <ry@tinyclouds.org> | 2018-12-17 23:14:22 -0500 |
| commit | 6e077e71fa27dbb993a49cda211c5385a76ca6aa (patch) | |
| tree | d3bba4c3d1d6ad96b0441ba0da78ec5232abcb6c | |
| parent | 81933b0f04b865cab3b42a257b333f37ccc441b7 (diff) | |
Implement append() to join 2 Uint8Array (denoland/deno_std#25)
Original: https://github.com/denoland/deno_std/commit/6f2811c27594b10dc7c6064eaa82cd0534b7a018
| -rw-r--r-- | textproto.ts | 7 | ||||
| -rw-r--r-- | textproto_test.ts | 11 |
2 files changed, 15 insertions, 3 deletions
diff --git a/textproto.ts b/textproto.ts index 4c4b92627..342d74b33 100644 --- a/textproto.ts +++ b/textproto.ts @@ -137,10 +137,13 @@ export class TextProtoReader { } } -function append(a: Uint8Array, b: Uint8Array): Uint8Array { +export function append(a: Uint8Array, b: Uint8Array): Uint8Array { if (a == null) { return b; } else { - throw Error("Not implemented"); + const output = new Uint8Array(a.length + b.length); + output.set(a, 0); + output.set(b, a.length); + return output; } } diff --git a/textproto_test.ts b/textproto_test.ts index 57ee99459..25c12b0e8 100644 --- a/textproto_test.ts +++ b/textproto_test.ts @@ -4,7 +4,7 @@ // license that can be found in the LICENSE file. import { BufReader } from "./bufio.ts"; -import { TextProtoReader } from "./textproto.ts"; +import { TextProtoReader, append } from "./textproto.ts"; import { stringsReader } from "./util.ts"; import { test, @@ -82,3 +82,12 @@ test(async function textprotoReadMIMEHeaderNonCompliant() { } */ }); + +test(async function textprotoAppend() { + const enc = new TextEncoder(); + const dec = new TextDecoder(); + const u1 = enc.encode("Hello "); + const u2 = enc.encode("World"); + const joined = append(u1, u2); + assertEqual(dec.decode(joined), "Hello World"); +}); |
