--- a/Base64Coder.st Mon Jan 12 16:24:45 2004 +0100
+++ b/Base64Coder.st Thu Jan 15 17:33:14 2004 +0100
@@ -13,7 +13,7 @@
"{ Package: 'stx:libbasic2' }"
ObjectCoder subclass:#Base64Coder
- instanceVariableNames:'buffer bits charCount peekByte atEnd'
+ instanceVariableNames:'buffer bits charCount peekByte atEnd lineLimit'
classVariableNames:'Base64Mapping Base64ReverseMapping'
poolDictionaries:''
category:'System-Storage'
@@ -94,6 +94,15 @@
].
Transcript cr.
[exEnd]
+ [exBegin]
+ |coder|
+
+ coder := Base64Coder on:'' writeStream.
+ coder nextPutAll:(0 to:200) asByteArray.
+ coder flush.
+
+ Transcript showCR:(coder contents).
+ [exEnd]
"
! !
@@ -120,6 +129,12 @@
^ self basicNew initialize
! !
+!Base64Coder methodsFor:'accessing'!
+
+lineLimit:something
+ lineLimit := something.
+! !
+
!Base64Coder methodsFor:'decoding'!
basicNext
@@ -244,6 +259,12 @@
buffer := (buffer bitShift:8) bitOr:aByte.
bits := bits + 8.
bits == 24 ifTrue:[
+ "RFC 2045 says: max 76 characters in one line"
+ (lineLimit notNil and:[charCount >= lineLimit]) ifTrue:[
+ stream cr.
+ charCount := 0.
+ ].
+
b4 := buffer bitAnd:16r3F.
b3 := (buffer bitShift:-6) bitAnd:16r3F.
b2 := (buffer bitShift:-12) bitAnd:16r3F.
@@ -254,13 +275,7 @@
nextPut:(Base64Mapping at:b3+1);
nextPut:(Base64Mapping at:b4+1).
- "RFC 2045 says: max 76 characters in one line"
- charCount >= 68 ifTrue:[
- stream cr.
- charCount := 0.
- ] ifFalse:[
- charCount := charCount + 4.
- ]
+ charCount := charCount + 4.
].
! !
@@ -275,6 +290,7 @@
initialize
buffer := bits := charCount := 0.
+ lineLimit := 76. "RFC 2045 says: max 76 characters in one line"
atEnd := false.
! !
@@ -373,7 +389,7 @@
!Base64Coder class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic2/Base64Coder.st,v 1.8 2003-09-03 13:24:19 stefan Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic2/Base64Coder.st,v 1.9 2004-01-15 16:33:14 cg Exp $'
! !
Base64Coder initialize!