diff --git a/collects/net/base64.rkt b/collects/net/base64.rkt index 087c927d8c..a95e4cd538 100644 --- a/collects/net/base64.rkt +++ b/collects/net/base64.rkt @@ -61,7 +61,7 @@ (base64-decode-stream (open-input-bytes src) s) (get-output-bytes s))) -(define (base64-encode src) +(define (base64-encode src [linesep #"\r\n"]) (let ([s (open-output-bytes)]) - (base64-encode-stream (open-input-bytes src) s (bytes 13 10)) + (base64-encode-stream (open-input-bytes src) s linesep) (get-output-bytes s))) diff --git a/collects/net/scribblings/base64.scrbl b/collects/net/scribblings/base64.scrbl index 0d3b6293ed..a3a8920558 100644 --- a/collects/net/scribblings/base64.scrbl +++ b/collects/net/scribblings/base64.scrbl @@ -8,11 +8,12 @@ utilities for Base 64 (MIME-standard) encoding and decoding.} @section[#:tag "base64-procs"]{Functions} -@defproc[(base64-encode [bstr bytes?]) bytes?]{ +@defproc[(base64-encode [bstr bytes?] [newline-bstr bytes? #"\r\n"]) bytes?]{ Consumes a byte string and returns its Base 64 encoding as a new byte string. The returned string is broken into 72-byte lines separated by -CRLF combinations, and always ends with a CRLF combination unless the +@racket[newline-bstr], which defaults to a CRLF combination, and the +result always ends with a @racket[newline-bstr] unless the input is empty.} diff --git a/collects/tests/racket/net.rktl b/collects/tests/racket/net.rktl index 9b86f927f5..33e1c297ea 100644 --- a/collects/tests/racket/net.rktl +++ b/collects/tests/racket/net.rktl @@ -12,4 +12,11 @@ net/qp mzlib/port) +(test #"" base64-encode #"") +(test #"" base64-encode #"" #"<>") +(test #"V2h5IGRvIGF4ZSBtdXJkZXJlcnMgb25seSBhdHRhY2sKV2hlbiB5b3UncmUgcGFydGlhbGx5\r\nIG51ZGUKT3IgeW91J3JlIHRha2luZyBhIGJhdGg=\r\n" + base64-encode #"Why do axe murderers only attack\nWhen you're partially nude\nOr you're taking a bath") +(test #"V2h5IGRvIGF4ZSBtdXJkZXJlcnMgb25seSBhdHRhY2sKV2hlbiB5b3UncmUgcGFydGlhbGx5<>IG51ZGUKT3IgeW91J3JlIHRha2luZyBhIGJhdGg=<>" + base64-encode #"Why do axe murderers only attack\nWhen you're partially nude\nOr you're taking a bath" #"<>") + (report-errs)