1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-23 15:16:54 -05:00

Implement append() to join 2 Uint8Array (denoland/deno_std#25)

Original: 6f2811c275
This commit is contained in:
Kevin (Kun) "Kassimo" Qian 2018-12-17 23:14:22 -05:00 committed by Ryan Dahl
parent 81933b0f04
commit 6e077e71fa
2 changed files with 15 additions and 3 deletions

View file

@ -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;
}
}

View file

@ -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");
});