tar: Couple of optimizations.

db4
Doug Coleman 2014-11-01 23:11:35 -07:00
parent 21b4e31d60
commit cbe72a7605
1 changed files with 5 additions and 4 deletions

View File

@ -3,7 +3,8 @@
USING: accessors byte-arrays combinators io io.backend USING: accessors byte-arrays combinators io io.backend
io.directories io.encodings.binary io.files io.files.links io.directories io.encodings.binary io.files io.files.links
io.pathnames io.streams.byte-array io.streams.string kernel io.pathnames io.streams.byte-array io.streams.string kernel
math math.parser namespaces sequences strings summary ; math math.parser namespaces sequences strings summary
typed ;
IN: tar IN: tar
CONSTANT: zero-checksum 256 CONSTANT: zero-checksum 256
@ -22,7 +23,7 @@ ERROR: checksum-error header ;
: trim-string ( seq -- newseq ) [ "\0 " member? ] trim ; : trim-string ( seq -- newseq ) [ "\0 " member? ] trim ;
: read-c-string ( n -- str/f ) : read-c-string ( n -- str/f )
read [ zero? ] trim-tail [ f ] when-empty >string ; read [ zero? ] trim-tail "" like ;
: read-tar-header ( -- obj ) : read-tar-header ( -- obj )
\ tar-header new \ tar-header new
@ -43,8 +44,8 @@ ERROR: checksum-error header ;
8 read trim-string oct> >>devminor 8 read trim-string oct> >>devminor
155 read-c-string >>prefix ; 155 read-c-string >>prefix ;
: checksum-header ( seq -- n ) TYPED: checksum-header ( seq: byte-array -- n )
148 cut-slice 8 tail-slice [ sum ] bi@ + 256 + ; 148 cut-slice 8 tail-slice [ 0 [ + ] reduce ] bi@ + 256 + >fixnum ;
: read-data-blocks ( tar-header -- ) : read-data-blocks ( tar-header -- )
dup size>> 0 > [ dup size>> 0 > [