Skip to content

How to retrieve blob with binary content? #83

Closed

Description

@philschatz

Hello! I tried to retrieve a binary blob (a 13k PNG file) using the #wip branch (on OSX):

Git.Repo.open(REPO_PATH, function(error, repo) {
  repo.getBlob(oid, function(error, blob) {
    var content = blob.content();
    if (blob.isBinary()) {
      fs.writeFileSync('BROKEN.png', content);
    }
  });
});

The first 4 or 5 bytes seem to match (they are ffd8 ffe0 00) but the rest of the bytes seem to be random memory; they change on subsequent retrievals of the same blob.

However, text files seem to work. Am I doing something dumb?

Activity

  1. philschatz commented on Sep 4, 2013

    @philschatz
    ContributorAuthor

    Also, a little self-contained repo that illustrates the problem: https://github.com/philschatz/nodegit-sample

  2. ghost assigned on Sep 5, 2013
  3. nkallen commented on Sep 5, 2013

    @nkallen
    Contributor

    Thanks for the self-contained repo, it saved me a ton of time fixing the problem. The latest wip a9ee1dc should fix this problem:

    Old code

    % node test.js 
    Writing a binary blob to disk: BROKEN.png
    % diff lena.png BROKEN.png 
    Binary files lena.png and BROKEN.png differ

    New code

    % node test.js 
    Writing a binary blob to disk: BROKEN.png
    % diff lena.png BROKEN.png 
    %

    I copied/pasted the solution from the commenter Jonathan Wiepert from http://www.samcday.com.au/blog/2011/03/03/creating-a-proper-buffer-in-a-node-c-addon/ -- hopefully this is a valid solution!

  4. philschatz commented on Sep 5, 2013

    @philschatz
    ContributorAuthor

    Thanks, it works great! For what it's worth, I'm using nodegit to make a local test suite for https://github.com/philschatz/octokit.js (JS client for GitHub's API) which is used in a GitHub eBook editor: https://github.com/philschatz/github-book

  5. added a commit that references this issue on Oct 27, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions