GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — datastore: blob value is lost · Issue #301 · googleapis/google-cloud-node

datastore: blob value is lost #301

New issue
Copy link
New issue
Copy link
Closed
#3520
#302
Closed
datastore: blob value is lost#301
#3520
#302
Copy link
Assignees
stephenplusplus
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.
Milestone
Datastore Stable

Description

@pgirard
pgirard
opened on Nov 15, 2014
Issue body actions

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.

Activity

Next
  1. ryanseys commented on Nov 16, 2014

    @ryanseys
    ryanseys
    on Nov 16, 2014
    Contributor
    More actions

    I can reproduce this issue. It appears that the property.blob_value is for some reason the entire ByteBuffer object for the entire response. When I decoded the protobuf response and looked for the geometry value, it's set to:

    blob_value:
       { buffer: <Buffer 0a 68 0a 66 0a 2d 0a 16 1a 14 73 7e 73 6f 79 2d 74 72 61 6e 73 64 75 63 65 72 2d 36 39 34 12 13 0a 08 4c 6f 63 61 74 69 6f 6e 10 80 80 80 80 af c8 80 09 ...>,
         offset: 85,
         markedOffset: -1,
         limit: 106,
         littleEndian: true,
         noAssert: false }

    This is what propertyToValue also sees. property.blob_value instanceof ByteBuffer is true in this case.
    In fact, if you print out the hex value for the entire ByteBuffer, you can see your data is in tact:

    property.blob_value.buffer.toString('hex')

    Output:

    0a680a660a2d0a161a14737e736f792d7472616e7364756365722d36393412130a084c6f636174696f6e108080808080e4d108120f0a02696422098a01063131332d313612240a0867656f6d657472792218920115010100000000000000000059400000000000006940
    

    That 010100000000000000000059400000000000006940 at the end is your location.

    But then things get really weird when you decode the original response buffer.

    In datastore/lib/request.js#makeAuthorizedRequest, we get a buffer. We then decode it using pbResponse.decode(buffer) and get a nice decoded object we can traverse in javascript.

    If we set that decoded to var decoded = pbResponse.decode(buffer); and then traverse to the geometry value decoded.found[0].entity.property[1].value.blob_value we get an ByteBuffer object much like the one at the top of this post. In fact, if we get the buffer property in that object, that is decoded.found[0].entity.property[1].value.blob_value.buffer and compare it to our ORIGINAL buffer we got fresh from the server, they are exactly the same. That is, the decoded buffer contains the original buffer. Recursion is awesome!

    I don't know enough about protobufs to fix this issue or even to say this is right or wrong but it's blowing my mind. From first glance, it looks like a bug in the protobuf.js library but a second opinion would be great.

  2. pgirard commented on Nov 16, 2014

    @pgirard
    pgirard
    on Nov 16, 2014
    Author
    More actions

    Wow, nice job digging into this. Thanks! My whole experience with protocol buffers extends back to just last Wednesday so consider me an interested bystander for now.

  3. ryanseys commented on Nov 16, 2014

    @ryanseys
    ryanseys
    on Nov 16, 2014
    Contributor
    More actions

    I figured it out! As you can see in the ByteBuffer object above, it has an offset and a limit. So we just need to use that to return the bytes you want! Luckily, ByteBuffer objects have a method to do just that, and viola, a one-line fix :) See 2d76a12

  4. pgirard commented on Nov 17, 2014

    @pgirard
    pgirard
    on Nov 17, 2014
    Author
    More actions

    Awesome, thanks so much! Got to love one-line fixes.

  5. stephenplusplus
    closed this as completedin #302on Nov 17, 2014
  6. jgeewax
    added
    api: datastoreIssues related to the Datastore API.
    type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.
    on Feb 2, 2015
  7. jgeewax
    added this to the Datastore Stable milestone on Feb 2, 2015
  8. yoshi-automation
    added
    🚨This issue needs some love.
    triage meI really want to be triaged.
    on Apr 6, 2020
  9. JustinBeckwith
    assigned
    stephenplusplus
    on Feb 1, 2021
  10. chingor13
    added a commit that references this issue on Aug 22, 2022

    build: set AUTOSYNTH_MULTIPLE_COMMITS=true for context aware commits (#…

    c11e844
  11. sofisl
    added a commit that references this issue on Sep 15, 2022

    chore(deps): update dependency @types/sinon to v9 (#301)

    8e9b06a
  12. sofisl
    added 2 commits that reference this issue on Oct 12, 2022

    chore: release 2.0.0 (#301)

    554a43d

    fix(deps): update dependency @google-cloud/common to v3 (#301)

    c654b48
  13. 25 remaining items

  14. miguelvelezsa
    added 2 commits that reference this issue on Jan 28, 2026

    Release v3.0.1 (#301)

    ac51388

    chore(main): release 3.0.0 (#301)

    cdd3cba
  15. sofisl
    added 3 commits that reference this issue on Feb 3, 2026

    fix(build): fix Kokoro release script (#301)

    b64c4ef

    chore(deps): update dependency eslint-plugin-node to v9 (#301)

    91848df

    Release v3.0.1 (#301)

    3d9e961
  16. GautamSharda
    added a commit that references this issue on Feb 5, 2026

    build: check for 404s when generating docs (#301)

    341e1ec
  17. sofisl
    added a commit that references this issue on Feb 17, 2026

    Release v3.0.1 (#301)

    f56c742
  18. GautamSharda
    added 3 commits that reference this issue on Feb 23, 2026

    build: check for 404s when generating docs (#301)

    2a488b8

    chore(deps): update dependency @types/node to v18 (#301)

    f0966e4

    build: check for 404s when generating docs (#301)

    4bc3a9e
  19. sofisl
    added a commit that references this issue on Feb 26, 2026

    Release nodejs-spanner v2.0.0 (#301)

    a8ddaa3
  20. GautamSharda
    added 4 commits that reference this issue on Mar 5, 2026

    chore(deps): update dependency bignumber.js to v8 (#301)

    40c70a7

    chore(main): release 3.0.0 (#301)

    b0e7983

    chore(main): release 3.0.0 (#301)

    68f955d

    chore(deps): upgrade @google-cloud/projectify to v0.3.2 (#301)

    a8a2682
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @stephenplusplus
    stephenplusplus

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

    Milestone

    • Datastore Stable

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.