ITrust / angular-xmlrpc

An AngularJS service which provides XML-RPC communication methods.
Apache License 2.0
11 stars 13 forks source link

Fix base64 encoding up to 128MiB and unicode characters #9

Open tympanix opened 7 years ago

tympanix commented 7 years ago

I found a bug where a Uint8Array could not be marshaled into base64 due to the relatively small call stack size of Javascript (I suspect recursion). The old limit was 128KiB. I was able to increase the size to 128MiB (10x old limit) before a RangeError: Invalid string length is thrown.

Furthermore, xml2json of base64 now returns an Uint8array of the data converted back from base64 to binary (opposed to just removing the base64 tag and returning the base64 content). It handles unicode characters as described here both to and from base64. Since this is in contradiction with the previous implementation, I have issued a new minor version.

tympanix commented 7 years ago

Base64 encoding of text works but binary data (from typed arrays) still seems problematic. One may have to resolve to one of the solutions [found here](https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding#Solution_.232_.E2.80.93_rewriting_atob()_and_btoa()_using_TypedArrays_and_UTF-8) which involves using polyfill. Closing momentarily. I will get back when a solution is found.

tympanix commented 7 years ago

Now supports binary base64 conversion through base64-js. I have added base64-js as an dependency, which means you will have to include the script in your browser for base64 encoding to work:

<script src="base64js.min.js"></script>

Achieving robust base64 encoding/decoding is problematic without this polyfill if you don't like having third party dependencies. I have been testing with real world files, which works flawlessly.

tympanix commented 6 years ago

Bump!