Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

binary request for static maps #119

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

binary request for static maps #119

wants to merge 1 commit into from

Conversation

cmyip
Copy link

@cmyip cmyip commented Jun 11, 2016

This fixes staticMaps function by properly setting request configuration

@fabriziomoscon
Copy link
Collaborator

Hi @cmyip thanks for contributing. Could you please point me to the documentation page so I can check the binary parameter and possibly add some info to the README?

@cmyip
Copy link
Author

cmyip commented Jul 19, 2016

hi @fabriziomoscon no reference found, but it was a stack overflow question:
http://stackoverflow.com/questions/14855015/getting-binary-content-in-node-js-using-request

@fabriziomoscon
Copy link
Collaborator

I found a test
https://github.com/request/request/blob/master/tests/test-body.js#L51-L55
and docs

encoding - Encoding to be used on setEncoding of response data. If null, the body is returned as a Buffer. Anything else (including the default value of undefined) will be passed as the encoding parameter to toString() (meaning this is effectively utf8 by default). (Note: if you expect binary data, you should set encoding: null.)

I think this is the relevant source code from request: https://github.com/request/request/blob/master/request.js#L1012-L1045

Although I think it is counter intuitive to set something to binary to achieve a null value. Perhaps we could consider a condition that checks whether encoding is null (since it is a function parameter it is null only if the user has specified it so, opposite to undefined where the user omits it).

if (encoding == null) {
    options.encoding = null;
} else if (encoding) { // we check this so we don't assume that request is checking for undefined
    options.encoding = encoding;
}

What do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants