Skip to content

datastore: blob value is lost #301

@pgirard

Description

@pgirard

I'm trying to save a Buffer as a property. From what I can see this should be possibe. In this example the Buffer contains 21 bytes:

dataset.save({
  key: dataset.key('Location'),
  data: {
    id: '113-16',
    geometry: new Buffer('010100000000000000000059400000000000006940', 'hex')
  }
}, function (err, key) {
  console.log(err || key);
});

However when I retrieve the entity I get a Buffer with zero length.

dataset.get(dataset.key([ 'Location', 5707702298738688 ]), function (err, entity) {
  console.log(err || entity.data.geometry.length);
});

In your lib/datastore/entity.js, function propertyToValue at line 362 you're creating a Buffer with the property.blob_value as base64:

  if (exists(property.blob_value)) {
    return new Buffer(property.blob_value, 'base64');
  }

When I debugged at this point I found that property.blob_value was a ByteBufferNB object, not a base64 string. I'm wondering if you meant to base64 encode the original value in function valueToProperty at line 430:

  if (v instanceof Buffer) {
    p.blob_value = v;    //  should it be v.toString('base64') ?
    return p;
  }

But that doesn't make sense since the datastore_v1.proto file defines blob_value as bytes not string at line 111:

  optional string blob_key_value = 16;

I suppose I could simply store my data directly as a base64-encoded string. But I'd prefer the compactness and efficiency of binary storage if possible.

Metadata

Metadata

Labels

🚨This issue needs some love.api: datastoreIssues related to the Datastore API.triage meI really want to be triaged.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions