 
 <PRIVATE
 
-: write-header ( len -- )
-    dup "Length: %d, %xh\n" printf ;
-
-CONSTANT: line# "00000000h: "
+CONSTANT: line# "00000000  "
 
 : inc-line# ( -- )
     7 [ CHAR: 0 = over 0 > and ] [

    ] do while drop ;

: reset-line# ( -- )
    7 [ CHAR: 0 swap line# set-nth ] each-integer ;

CONSTANT: hex-digits $[
    256 <iota> [ >hex 2 CHAR: 0 pad-head " " append ] map

:: hexdump-bytes ( from to bytes -- )
    reset-line#
    to from - :> len
    len 16 /mod
    [ [ 16 * dup 16 + bytes write-hex-line ] each-integer ]
    [ [ len swap - len bytes write-hex-line ] unless-zero ] bi*
    len "%08x\n" printf ;

: hexdump-stream ( stream -- )
    reset-line# 0 swap [
        all-bytes [ write-hex-line ] [ length + ] bi
    ] 16 (each-stream-block) "%08x\n" printf ;

PRIVATE>

