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

Encoding parameter #67

Open
rap2hpoutre opened this issue Jun 1, 2018 · 1 comment
Open

Encoding parameter #67

rap2hpoutre opened this issue Jun 1, 2018 · 1 comment

Comments

@rap2hpoutre
Copy link

Using request, I can add options about encoding: encoding: 'latin1'. Is it possible with r2?

@DevBrent
Copy link

DevBrent commented Aug 31, 2018

It looks like encoding for request is used when getting text for the response data. Fetch is a browser-first implementation that explicitly is designed for UTF-8 so you'll want to fall back to DataView and TextEncoding APIs (or use polyfills).

const ab = await (await r2.get(url).response).arrayBuffer();
const dataView = new DataView(ab); // May only need this in the browser, use ab in place if so.
const decoder = new TextDecoder('latin1');
console.log(decoder.decode(dataView));

https://developers.google.com/web/updates/2014/08/Easier-ArrayBuffer-String-conversion-with-the-Encoding-API
https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch
https://nodejs.org/api/string_decoder.html
https://nodejs.org/api/buffer.html

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

No branches or pull requests

2 participants