I have a buffer which is being populated with a bunch of base64 strings. I want a way to decode those string and be able to read all of the base64 strings in that buffer.
const slugId1 = 'YriU6QbcQj6xtdUUosJTxA==';
const slugId2 = 'Su7Zvq1vRca/teTNfEmfNQ==';
const SLUGID_SIZE = 16;
let buffer = Buffer.alloc(SLUGID_SIZE * 2);
buffer.write(slugId1, 0, SLUGID_SIZE, 'base64');
buffer.write(slugId2, SLUGID_SIZE, SLUGID_SIZE, 'base64');
console.log(buffer.toString('base64', 0, SLUGID_SIZE));
console.log(buffer.toString('base64', SLUGID_SIZE, SLUGID_SIZE));
What I'm getting:
YriU6QbcQj6xtdUUosJTxA==
What I expect to get:
YriU6QbcQj6xtdUUosJTxA==
Su7Zvq1vRca/teTNfEmfNQ==
Any help is appreciated.
buffer.toString2nd and 3rd parameter arestartandend- given you give the same value for start and end, the result is of course zero length