Skip to content

Commit

Permalink
feat: change BSONification to string rather than Uint8Array
Browse files Browse the repository at this point in the history
While Uint8Array did same some bytes the added complexity of working with byte arrays isn't deemed worth it.
  • Loading branch information
hollandjake committed Sep 9, 2024
1 parent e4d1c71 commit 0b741fb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/pointer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('toString', () => {

test('toBSON', ({ expect }) => {
const p = new Pointer(['foo', '\u03A9', 0]);
expect(p.toBSON()).toEqual(new Uint8Array([47, 102, 111, 111, 47, 206, 169, 47, 48]));
expect(p.toBSON()).toEqual('/foo/\u03A9/0');
});

describe('from', () => {
Expand Down
8 changes: 4 additions & 4 deletions src/pointer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TextDecoder, TextEncoder } from 'util';
import { TextDecoder } from 'util';
import { MissingError, PointerError } from './error';

type Token = string | number | { toString: () => string };
Expand Down Expand Up @@ -112,10 +112,10 @@ export class Pointer {
}

/**
* Efficiently convert pointers to binary array for compression storage size
* Convert pointers to string for easy BSONification
*/
public toBSON(): Uint8Array {
return new TextEncoder().encode(this.toString());
public toBSON(): string {
return this.toString();
}

public toJSON() {
Expand Down

0 comments on commit 0b741fb

Please sign in to comment.