Skip to content

Commit 6ce2e5b

Browse files
authored
chore: remove the blob error workaround (#1072)
* remove the blob error workaround An error with code 3 was thrown when the test code was run before the workaround was added and before the proto changes were made. Now that the proto changes have been made, the workaround is no longer required so it is removed in this commit. * return encode test to original Change a test so that it matches what it originally was back in 2020.
1 parent e11cf6c commit 6ce2e5b

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

src/entity.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -657,10 +657,7 @@ export namespace entity {
657657
}
658658

659659
if (value instanceof Buffer) {
660-
// Convert the buffer to a base 64 string to workaround a bug of
661-
// protobufs encoding empty buffer.
662-
// See https://github.com/googleapis/nodejs-datastore/issues/755
663-
valueProto.blobValue = value.toString('base64');
660+
valueProto.blobValue = value;
664661
return valueProto;
665662
}
666663

system-test/datastore.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,19 @@ describe('Datastore', () => {
543543
await datastore.delete(personKey);
544544
});
545545

546+
it('should save with an empty buffer', async () => {
547+
const key = datastore.key(['TEST']);
548+
const result = await datastore.save({
549+
key: key,
550+
data: {
551+
name: 'test',
552+
blob: Buffer.from([]),
553+
},
554+
});
555+
const mutationResult = result.pop()?.mutationResults?.pop();
556+
assert.strictEqual(mutationResult?.key?.path?.pop()?.kind, 'TEST');
557+
});
558+
546559
describe('entity types', () => {
547560
it('should save and decode an int', async () => {
548561
const integerValue = 2015;

test/entity.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,7 @@ describe('entity', () => {
849849
const value = Buffer.from('Hi');
850850

851851
const expectedValueProto = {
852-
blobValue: value.toString('base64'),
852+
blobValue: value,
853853
};
854854

855855
assert.deepStrictEqual(entity.encodeValue(value), expectedValueProto);

0 commit comments

Comments
 (0)