Changeset 14252 in project


Ignore:
Timestamp:
04/15/09 01:00:50 (11 years ago)
Author:
Jim Ursetto
Message:

Changes applied for zbigniew (71.201.84.72) through svnwiki:

base64: add some examples

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wiki/eggref/4/base64

    r14251 r14252  
    1818<parameter>(base64-line-breaks BOOLEAN) [default: #f]</parameter>
    1919
    20 If {{#t}}, the decoder inserts a CRLF into the output string every 76 output characters (57 input characters).  A CRLF will also be appended to the final line, only if it was a partial one (between 1 and 75 output characters).
     20If {{#t}}, the decoder inserts a CRLF into the output string every 76 output characters (57 input characters).  A CRLF will also be appended to the final line, only if it was a partial one (between 1 and 75 output characters).  In a UTF8 environment, character means "byte".
    2121
    2222== Examples
     
    5252     (lambda (p) (read-string #f p)))))
    5353
     54The last script reads the file completely into memory.  You can use a constant amount of memory and obtain the same output by
     55reading in multiples of 57 characters and displaying incrementally:
     56
     57 #!/Users/jim/local/bin/csi4 -script
     58 (use base64)
     59 (base64-line-breaks #t)
     60 
     61 (call-with-input-file (car (command-line-arguments))
     62   (lambda (p)
     63     (let loop ()
     64       (let ((s (read-string (* 57 60) p)))
     65         (cond ((string=? s ""))
     66               (else
     67                (display (base64-encode s))
     68                (loop)))))))
     69
     70For properly formatted output in a UTF-8 environment, you should read 57 bytes instead of 57 characters, as these procedures operate on octets.
    5471
    5572== About this egg
Note: See TracChangeset for help on using the changeset viewer.