base85: change to not pad encoding, fix output bug.
parent
1ff2722b15
commit
4fbc726b1a
|
@ -3,5 +3,8 @@ USING: base85 kernel strings tools.test ;
|
|||
{ t } [ "Hello, world" dup >base85 base85> >string = ] unit-test
|
||||
{ t } [ "ready" dup >base85 base85> >string = ] unit-test
|
||||
|
||||
{ "NM!&3" } [ "He" >base85 >string ] unit-test
|
||||
{ "NM!" } [ "He" >base85 >string ] unit-test
|
||||
{ t } [ "He" dup >base85 base85> >string = ] unit-test
|
||||
|
||||
{ "00" } [ B{ 0 } >base85 >string ] unit-test
|
||||
{ "\0" } [ "00" base85> >string ] unit-test
|
||||
|
|
|
@ -27,7 +27,12 @@ CONSTANT: alphabet
|
|||
4 pick stream-read dup length {
|
||||
{ 0 [ 3drop ] }
|
||||
{ 4 [ encode4 write-lines (encode-base85) ] }
|
||||
[ drop 4 0 pad-tail encode4 write-lines (encode-base85) ]
|
||||
[
|
||||
drop
|
||||
[ 4 0 pad-tail encode4 ]
|
||||
[ length neg 4 rem head-slice* write-lines ] bi
|
||||
(encode-base85)
|
||||
]
|
||||
} case ;
|
||||
|
||||
PRIVATE>
|
||||
|
@ -40,15 +45,19 @@ PRIVATE>
|
|||
|
||||
<PRIVATE
|
||||
|
||||
: decode5 ( seq -- )
|
||||
0 [ [ 85 * ] [ base85>ch ] bi* + ] reduce 4 >be
|
||||
[ zero? ] trim-tail-slice write ; inline
|
||||
: decode5 ( seq -- seq' )
|
||||
0 [ [ 85 * ] [ base85>ch ] bi* + ] reduce 4 >be ; inline
|
||||
|
||||
: (decode-base85) ( stream -- )
|
||||
5 "\n\r" pick read-ignoring dup length {
|
||||
{ 0 [ 2drop ] }
|
||||
{ 5 [ decode5 (decode-base85) ] }
|
||||
[ malformed-base85 ]
|
||||
{ 5 [ decode5 write (decode-base85) ] }
|
||||
[
|
||||
drop
|
||||
[ 5 CHAR: ~ pad-tail decode5 ]
|
||||
[ length neg 5 rem head-slice* write ] bi
|
||||
(decode-base85)
|
||||
]
|
||||
} case ;
|
||||
|
||||
PRIVATE>
|
||||
|
|
Loading…
Reference in New Issue