]> gitweb.factorcode.org Git - factor.git/blob - core/io/streams/byte-array/byte-array.factor
Refactor all usages of >r/r> in core to use dip, 2dip, 3dip
[factor.git] / core / io / streams / byte-array / byte-array.factor
1 USING: byte-arrays byte-vectors kernel io.encodings io.streams.string
2 sequences io namespaces io.encodings.private accessors ;
3 IN: io.streams.byte-array
4
5 : <byte-writer> ( encoding -- stream )
6     512 <byte-vector> swap <encoder> ;
7
8 : with-byte-writer ( encoding quot -- byte-array )
9     [ <byte-writer> ] dip [ output-stream get ] compose with-output-stream*
10     dup encoder? [ stream>> ] when >byte-array ; inline
11
12 : <byte-reader> ( byte-array encoding -- stream )
13     [ >byte-vector dup reverse-here ] dip <decoder> ;
14
15 : with-byte-reader ( byte-array encoding quot -- )
16     [ <byte-reader> ] dip with-input-stream* ; inline