philschatz / octokit.js

Unmaintained Client for GitHub's API. Instead, check out:
https://github.com/philschatz/octokat.js
BSD 3-Clause "New" or "Revised" License
101 stars 28 forks source link

Uploading binary data #44

Open ssured opened 10 years ago

ssured commented 10 years ago

Thanks for the library!

When writing binary data to GitHub the API seems a little weird. Consider buffer to contain a gif image.

This code does not work:

branch.write({
  "image.gif": {
    isBase64: true,
    content: buffer.toString('base64')
  }
});

This code works:

branch.write({
  "image.gif": {
    isBase64: true,
    content: buffer.toString('binary')
  }
});

It feels really weird to provide a binary string and specifying isBase64

https://github.com/philschatz/octokit.js/blob/master/octokit.js#L764-L766 causes the problem. Some simple API aligning will fix the issue.

philschatz commented 10 years ago

Thanks for the issue. Are you using this library in NodeJS or in the browser?

Is renaming isBase64 to isBinary sufficient?

ssured commented 10 years ago

I am using NodeJS right now.

Yes, renaming to isBinary is sufficient.

Even nicer would be to check for a Buffer (content instanceof Buffer) object, if so, consider it binary data and call content.toString(‘base64’). Browsers < IE10 need a little care in that case http://caniuse.com/typedarrays

Kedrigern commented 10 years ago

Hi, I have similar problem. Is relevant? Is this solved?

Details and minimal working example.