All files / src/encodings utf8.ts

100% Statements 5/5
100% Branches 0/0
100% Functions 2/2
100% Lines 5/5

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14    19x 19x   19x   207474x       101042x    
import { Encoding } from "../types";
 
const encoder = /*@__PURE__*/ new TextEncoder();
const decoder = /*@__PURE__*/ new TextDecoder();
 
export const utf8: Encoding<string> = {
  encode(ctx, data) {
    ctx.i += encoder.encodeInto(data, ctx.bytes.subarray(ctx.i))
      .written as number;
  },
  decode: (ctx, size) =>
    decoder.decode(ctx.bytes.subarray(ctx.i, (ctx.i += size)))
};