Giter Club home page Giter Club logo

Comments (15)

sergeevabc avatar sergeevabc commented on July 3, 2024 3

@aklomp, you mean I have to download that branch and compile it myself? o_O

from base64.

aklomp avatar aklomp commented on July 3, 2024 1

@sergeevabc Well yes, how else do you get a binary? This project does not publish any binaries.

But anyway, I think I'll merge the branch today because it fixes the issue, and create a follow-up issue to deal with the slow decoding. The fix works, it's pretty trivial and I tested it locally. It's just quite slow because it scans the input twice.

from base64.

aklomp avatar aklomp commented on July 3, 2024

Sorry, fat-fingered the post button.

from base64.

aklomp avatar aklomp commented on July 3, 2024

Hi, this is caused by a change in behavior of the bin/base64 utility since 0.5.0. In order to be bug-compatible with "standard" base64, it now always outputs a newline after the output. Since \n is not a valid base64 char, an error is thrown when the output is piped back into the decoder.

The fix is to run it as echo foo | ./build/bin/base64 -w0 | ./build/bin/base64 -d. The -w0 option suppresses line-buffered output.

from base64.

jirutka avatar jirutka commented on July 3, 2024

I hope you don’t consider this totally unexpected and confusing behaviour a feature. Since newline is not a valid character in base64, you can easily strip the trailing newline in the input to the decoder.

from base64.

aklomp avatar aklomp commented on July 3, 2024

The base64 utility is intended as a demo project for the base64 library, to show how to integrate the library into a codebase. I don't consider it a core feature. Before the last release, the base64 library was very simple and behaved as a dumb pipe. stdout could be piped to stdin and all was well.

But over the years a few issues have been raised (#8 is the one I could find quickly) that were caused by the fact that the behavior was not identical to the system base64. So in issue #115 I decided to fix that complaint and go for bug compatibility. So now the program always emits a trailing newline and always line-breaks the output by default. Gross, I agree, because I like dumb pipes, but it upholds the principle of least surprise.

But, and this is where you have a point, it seems like I didn't do a perfect job, because upon checking, the system base64 does seem to eat newlines, as demonstrated by:

echo foo | base64 | base64 -d

So I guess this issue is now about stripping newlines from the input.

from base64.

aklomp avatar aklomp commented on July 3, 2024

Possible connection to #33.

from base64.

sergeevabc avatar sergeevabc commented on July 3, 2024

Windows 7 x64 user here. Looking forward to test a fixed version.

from base64.

aklomp avatar aklomp commented on July 3, 2024

I pushed an issue126 branch which fixes this issue, but in benchmarks it's about twice as slow as the system base64's decoder on the same large input file. Probably because the algorithm is really naive and checks the input bytewise for \n.

I guess I can merge it because a working but slow program is preferable over a non-working program, but it sucks to admit defeat to the system base64 :)

from base64.

aklomp avatar aklomp commented on July 3, 2024

Found the speed regression. Don't write to stdout in the inner loop :) Anyway, now the timing is competitive again. Will merge soon.

from base64.

sergeevabc avatar sergeevabc commented on July 3, 2024

Testing base64 0.5.2 built with w64devkit on Windows 7 x64. Oh my, the executable turned out to be almost 10 times larger than the source (116658 vs 12913 bytes).

$ busybox echo -n Z2l0aHVi | base64.exe -d
github

$ busybox echo -n Z2l0aHViIAo= | base64.exe -d
github

$ busybox echo -n Z2l0aHViCg== | base64.exe -d
github

$ busybox echo -n Z2l0aHViIA0K | base64.exe -d
github

I guess the devil is in the details like spaces, carriage returns and line feeds?

from base64.

aklomp avatar aklomp commented on July 3, 2024

@sergeevabc I don't quite understand your comment. Are you reporting a bug?

Those strings seem to decode fine for me, including the whitespace, as shown with xxd:

$ echo -n Z2l0aHVi | bin/base64 -d | xxd
00000000: 6769 7468 7562                           github
$ echo -n Z2l0aHViIAo= | bin/base64 -d | xxd
00000000: 6769 7468 7562 200a                      github .
$ echo -n Z2l0aHViCg== | bin/base64 -d | xxd
00000000: 6769 7468 7562 0a                        github.
$ echo -n Z2l0aHViIA0K | bin/base64 -d | xxd
00000000: 6769 7468 7562 200d 0a                   github ..

About the binary size, not sure why it's so much larger, but I think static linking might have something to do with it.

from base64.

sergeevabc avatar sergeevabc commented on July 3, 2024

There's an issue indeed, @aklomp.

from base64.

aklomp avatar aklomp commented on July 3, 2024

@sergeevabc This issue has been closed. Please open a new issue if you want to file a bug report. By the way, I can't reproduce this in Linux; are you sure you are using the latest version?

from base64.

sergeevabc avatar sergeevabc commented on July 3, 2024

@aklomp, by the way, you should consider displaying the version so that we don't have to guess, redownload and recompile the source code. Yes, I have the latest version (0.5.2). And I suspect that issue is related to handling CRLF.

from base64.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.