-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
adds base64 decoding (fixes #5656) #9157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9d4d0c3
adds base64 decoding (fixes #5656)
f529f93
improves efficiency, moves alias to deprecated.jl, removes trailing w…
dbe0b02
Merge remote-tracking branch 'upstream/master' into base64_decode_#5656
487c349
update old names in other files
14e2ced
avoid creating new array for each 4 byte block
58956c0
Merge remote-tracking branch 'upstream/master' into base64_decode_#5656
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -246,6 +246,10 @@ const Uint128 = UInt128 | |
@deprecate iround(x) round(Integer,x) | ||
@deprecate iround{T}(::Type{T},x) round(T,x) | ||
|
||
export Base64Pipe, base64 | ||
const Base64Pipe = Base64EncodePipe | ||
const base64 = base64encode | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this be a |
||
|
||
@deprecate prevind(a::Any, i::Integer) i-1 | ||
@deprecate nextind(a::Any, i::Integer) i+1 | ||
|
||
|
@@ -254,3 +258,4 @@ const Uint128 = UInt128 | |
@deprecate squeeze(X, dims) squeeze(X, tuple(dims...)) | ||
|
||
@deprecate sizehint(A, n) sizehint!(A, n) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
|
||
const inputText = "Man is distinguished, not only by his reason, but by this singular passion from other animals, which is a lust of the mind, that by a perseverance of delight in the continued and indefatigable generation of knowledge, exceeds the short vehemence of any carnal pleasure." | ||
const encodedMaxLine76 = | ||
"""TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlz | ||
IHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2Yg | ||
dGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGlu | ||
dWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRo | ||
ZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4=""" | ||
|
||
# Encode and decode | ||
fname = tempname() | ||
f = open(fname, "w") | ||
opipe = Base64EncodePipe(f) | ||
write(opipe,inputText) | ||
close(opipe) | ||
close(f) | ||
f = open(fname, "r") | ||
ipipe = Base64DecodePipe(f) | ||
@test readall(ipipe) == inputText | ||
close(ipipe) | ||
close(f) | ||
rm(fname) | ||
|
||
# Encode to string and decode | ||
@test base64decode(base64encode(inputText)) == inputText | ||
|
||
# Decode with max line chars = 76 and padding | ||
ipipe = Base64DecodePipe(IOBuffer(encodedMaxLine76)) | ||
@test readall(ipipe) == inputText | ||
|
||
# Decode with max line chars = 76 and no padding | ||
ipipe = Base64DecodePipe(IOBuffer(encodedMaxLine76[1:end-1])) | ||
@test readall(ipipe) == inputText | ||
|
||
# Decode with two padding characters ("==") | ||
ipipe = Base64DecodePipe(IOBuffer(string(encodedMaxLine76[1:end-2],"=="))) | ||
@test readall(ipipe) == inputText[1:end-1] | ||
|
||
# Test incorrect format | ||
ipipe = Base64DecodePipe(IOBuffer(encodedMaxLine76[1:end-3])) | ||
@test_throws ErrorException readall(ipipe) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is wrong. It should be
readbytes
, notreadall
. The Base64-encoded data need not produce a valid UTF-8 string.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's definitely wrong... esp. since most uses of base64 encoding are to store binary data, not Unicode text...