![]() The resulting binary data then is put into urlsafe_b64encode(), yielding a URL-safe byte sequence. The following resources helped me assembling this test text:Īs you can see, the text is first encoded using the UTF-8 codec. The original text (the variable named text) is meant to contain code points from many different Unicode character blocks. ̃)!॒॑॓ஙசປຜἑἔℇ∆∇▆▇█ĭatab64 = urlsafe_b64encode (data ) print ( "text length: %s" % len (text ) ) print ( "urlsafe base64 representation of the binary data: \n \n%s" % datab64 ).# -*- coding: utf-8 -*- from _future_ import unicode_literals I’ll start with a Python snippet defining the original text and creating its URL-safe base64 representation: The original text and its URL-safe representation I’ll show two different methods for performing this task. Proceeding from here, I realized that there also is still no established way for decoding a binary blob into a DOMString using a given codec (UTF-8 in this case). Further below, I’ll show three different methods for executing this step. There is no obvious way for obtaining a binary blob from base64-encoded data. Unfortunately, there so far are no official and no established ways for performing steps 5.3 and 5.4 in a browser environment. Decode the binary blob into a DOMString containing the original text, using the UTF-8 codec.Decode the base64 string into a real binary data type ( Uint8Array, for instance).Transform URL-safe base64 representation to canonical base64 (replace _ and – characters).The data arrives as DOMString type (unicode text, so to say).Invert the entire procedure in the browser:.Let’s assume it ends up in a browser (in window.location, for instance). base64-encode the resulting binary data (and replace the URL-unsafe characters / and with, for instance, – and _). ![]() Encode the original text into binary data with the UTF-8 codec.Start with the original text, which is a sequence of unicode code points.With the right tools this should be a trivial process, shouldn’t it? For an AngularJS-based web application I am currently working on, I want to put arbitrary text information into a URL, send it to the client, and have it decoded by the browser.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |