From dbe90fa15e7d5adc9f5839203929b2b1ccca33b7 Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Mon, 20 Feb 2012 08:23:04 -0700 Subject: [PATCH] add optional newline argument to `base64-encode' original commit: a12f9831a34e64b4668a4833fb099506f4244aa6 --- collects/net/scribblings/base64.scrbl | 5 +++-- collects/tests/racket/net.rktl | 7 +++++++ 2 files changed, 10 insertions(+), 2 deletions(-) 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)