Changeset 14902 in project


Ignore:
Timestamp:
06/06/09 12:40:31 (11 years ago)
Author:
azul
Message:

Break base64 lines to make their length shorter than or equal to 76.

Location:
release/3/stream-base64
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • release/3/stream-base64/stream-base64.meta

    r9679 r14902  
    44 (synopsis
    55   "Performs lazy encoding and decoding of streams of characters to and from Base64")
    6  (needs srfi-40 stream-ext)
     6 (needs srfi-40 stream-ext embedded-test)
    77 (doc-from-wiki)
    88 (category parsing)
  • release/3/stream-base64/stream-base64.scm

    r1 r14902  
    2121
    2222(declare (export base64-decode base64-encode))
    23 (require-extension srfi-40 stream-ext)
     23(require-extension srfi-40 stream-ext embedded-test)
    2424
    2525(define *alphabet* "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/")
     
    4444  (transform 4 dig->num 6 (lambda (i) (integer->char (bitwise-and i 255))) #f 8 (constantly stream-null)))
    4545
     46(test-group break-lines
     47  (test (stream->string (break-lines (string->stream "1234") 2))
     48        "12\n34")
     49  (test (stream->string (break-lines (string->stream "12345") 2))
     50        "12\n34\n5")
     51  (test (stream->string (break-lines stream-null 2))
     52        ""))
     53
     54(define (break-lines input len)
     55  (stream-append
     56    (stream-take-safe input len)
     57    (let loop ((input (stream-drop-safe input len)))
     58      (if (stream-null? input)
     59        stream-null
     60        (stream-cons
     61          #\newline
     62          (stream-append
     63            (stream-take-safe input len)
     64            (loop (stream-drop-safe input len))))))))
     65
    4666(define base64-encode
    47   (transform 3 identity 8 num->dig #t 6 (lambda (r) (make-stream (- 3 r) #\=))))
     67  (break-lines
     68    (transform 3 identity 8 num->dig #t 6 (lambda (r) (make-stream (- 3 r) #\=)))
     69    76))
    4870
    4971(define (accum in stop getval shift)
Note: See TracChangeset for help on using the changeset viewer.