Skip to content

Commit

Permalink
fix: fix an algorithm error
Browse files Browse the repository at this point in the history
  • Loading branch information
mogeko committed Sep 28, 2024
1 parent f6ce5cf commit e6c6168
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/encoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ function encode6bit(b: number) {

function encode3bytes(b1: number, b2: number, b3: number) {
return encode6bit((b1 >> 2) & 0x3f).concat(
encode6bit(((b1 & 0x3) << 4) | ((b2 >> 4) & 0x3f)),
encode6bit(((b2 & 0xf) << 2) | ((b3 >> 6) & 0x3f)),
encode6bit((((b1 & 0x3) << 4) | (b2 >> 4)) & 0x3f),
encode6bit((((b2 & 0xf) << 2) | (b3 >> 6)) & 0x3f),
encode6bit(b3 & 0x3f),
);
}
Expand Down Expand Up @@ -61,13 +61,13 @@ if (import.meta.vitest) {
expect(encode6bit(64)).toStrictEqual("?");
});

it("append3bytes", () => {
it("encode3bytes", () => {
expect(encode3bytes(1, 2, 3)).toStrictEqual("0G83");
expect(encode3bytes(1, 2, 0)).toStrictEqual("0G80");
expect(encode3bytes(1, 0, 0)).toStrictEqual("0G00");
});

it("encode64", () => {
it("encode", () => {
expect(
encode(Buffer.from([75, 76, 74, 6, 0]).toString("binary")),
).toStrictEqual("IqnA1W00");
Expand Down

0 comments on commit e6c6168

Please sign in to comment.