Thread overview | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
April 07, 2016 How to set padding for base64 encoding | ||||
---|---|---|---|---|
| ||||
It's look like my data have padding that cause crush on function: std.file.write("output.png", Base64.decode(myimg)); > Invalid character: It's look like I should to use template function, but I can't figure out how to use it. Could anybody show example? My code: http://www.everfall.com/paste/id.php?pzpdgvtyb3ji https://dlang.org/phobos/std_base64.html#.Base64 |
April 07, 2016 Re: How to set padding for base64 encoding | ||||
---|---|---|---|---|
| ||||
Posted in reply to Suliman | On 07/04/2016 11:49 PM, Suliman wrote:
> It's look like my data have padding that cause crush on function:
> std.file.write("output.png", Base64.decode(myimg));
>> Invalid character:
>
> It's look like I should to use template function, but I can't figure out
> how to use it. Could anybody show example?
>
> My code:
> http://www.everfall.com/paste/id.php?pzpdgvtyb3ji
>
> https://dlang.org/phobos/std_base64.html#.Base64
"abc" strings are not multiline.
Use """abc""" for that purpose.
Also perhaps next time test with a smaller file.. say 1 by 1 with no extra chunks.
|
April 07, 2016 Re: How to set padding for base64 encoding | ||||
---|---|---|---|---|
| ||||
Posted in reply to rikki cattermole | On Thursday, 7 April 2016 at 11:59:09 UTC, rikki cattermole wrote:
> On 07/04/2016 11:49 PM, Suliman wrote:
>> It's look like my data have padding that cause crush on function:
>> std.file.write("output.png", Base64.decode(myimg));
>>> Invalid character:
>>
>> It's look like I should to use template function, but I can't figure out
>> how to use it. Could anybody show example?
>>
>> My code:
>> http://www.everfall.com/paste/id.php?pzpdgvtyb3ji
>>
>> https://dlang.org/phobos/std_base64.html#.Base64
>
> "abc" strings are not multiline.
> Use """abc""" for that purpose.
>
> Also perhaps next time test with a smaller file.. say 1 by 1 with no extra chunks.
If I wrap data with """ or ` .... ` I am getting same error. It's seems that problem that last charset is =
|
April 07, 2016 Re: How to set padding for base64 encoding | ||||
---|---|---|---|---|
| ||||
Posted in reply to Suliman | Create a range that would remove the newline characters from string, then decode from that. |
April 07, 2016 Re: How to set padding for base64 encoding | ||||
---|---|---|---|---|
| ||||
Posted in reply to Kagamin | On Thursday, 7 April 2016 at 12:19:48 UTC, Kagamin wrote:
> Create a range that would remove the newline characters from string, then decode from that.
std.file.write("output.png", Base64.decode(myimg.chomp));
The same error
|
April 07, 2016 Re: How to set padding for base64 encoding | ||||
---|---|---|---|---|
| ||||
Posted in reply to Suliman | chomp only trims the string at the beginning and at the end, not in the middle. |
April 07, 2016 Re: How to set padding for base64 encoding | ||||
---|---|---|---|---|
| ||||
Posted in reply to Suliman | On Thursday, 7 April 2016 at 12:24:06 UTC, Suliman wrote:
> On Thursday, 7 April 2016 at 12:19:48 UTC, Kagamin wrote:
>> Create a range that would remove the newline characters from string, then decode from that.
>
> std.file.write("output.png", Base64.decode(myimg.chomp));
>
> The same error
Anyway if you need to import a file inside your code probabily import works better.
Something like:
auto mystring = import("file.png");
So you don't need any decoding at runtime.
|
April 08, 2016 Re: How to set padding for base64 encoding | ||||
---|---|---|---|---|
| ||||
Posted in reply to Kagamin | On 08/04/2016 12:19 AM, Kagamin wrote:
> Create a range that would remove the newline characters from string,
> then decode from that.
Can confirm, its \n and \r that is causing the problems here.
|
April 07, 2016 Re: How to set padding for base64 encoding | ||||
---|---|---|---|---|
| ||||
Posted in reply to rikki cattermole | On Thursday, 7 April 2016 at 12:30:59 UTC, rikki cattermole wrote: > On 08/04/2016 12:19 AM, Kagamin wrote: >> Create a range that would remove the newline characters from string, >> then decode from that. > > Can confirm, its \n and \r that is causing the problems here. with: std.file.write("output.png", Base64.decode(myimg.replace("\r\n", ""))); I am getting same issue. But it should remove all new lines... |
April 08, 2016 Re: How to set padding for base64 encoding | ||||
---|---|---|---|---|
| ||||
Posted in reply to Suliman | On 08/04/2016 12:39 AM, Suliman wrote:
> On Thursday, 7 April 2016 at 12:30:59 UTC, rikki cattermole wrote:
>> On 08/04/2016 12:19 AM, Kagamin wrote:
>>> Create a range that would remove the newline characters from string,
>>> then decode from that.
>>
>> Can confirm, its \n and \r that is causing the problems here.
>
> with:
> std.file.write("output.png", Base64.decode(myimg.replace("\r\n", "")));
>
> I am getting same issue. But it should remove all new lines...
ok split myimg value into another file, remove all \r and \n separately via e.g. tr.
Then read it in, that's what I did.
|
Copyright © 1999-2021 by the D Language Foundation