Checking fetch for error
why is this so hard
- tags
- javascript
pako is a javascript implementation of the zlib library. I was trying to make it work when I was recreating the notepadtab but I was unable to make it work. Turns out that it's because I have no idea how JavaScript strings work. Not sure that it's actually clearer now, but this code works.
To use pako
, pass in the source data to pako.deflate
. This will give
you a Uint8Array
, which you need to convert back to a string for
window.btoa
to work – otherwise it will encode the string
representation of the array. Use String.fromCharCode
to make that
work.
To get things back, you need to do atob
to convert the base64 back to
an array of bytes. We then convert that to a string, and then that
into a Uint8 array, and inflate that using pako and then turn that again
into a string!
|
|
Then create a package.json
like this:
|
|
|
|
|
|
And open the console.
Previously
Next