Hi Joe, Just a quick note to say that "Learning Perl 6" by brian d foy has a section on reading binary files (pp.155-157). Check out the "Buf" object type, the ":bin" adverb, and the ".read" method. In particular, ".read" takes an argument specifying how many octets you want to read in.
HTH, Bill. On Sun, Oct 20, 2019 at 4:08 PM Joseph Brenner <doom...@gmail.com> wrote: > > Yes, you can call .comb on a file handle (which I hadn't realized) and > if you give it an integer as first argument, that treats it as a chunk > size... So stuff like this seems to work fine: > > my $fh = $file.IO.open; > my $chunk_size = 1000; > for $fh.comb( $chunk_size ) -> $chunk { > say $chunk.chars; # 10000 > say "~~~>>>", $chunk, "<<<<~~~"; > } > > But I see you tossed in the caveat "Assuming it is a text file": is > there a problem if it's some other type of file? > > > > > > On 10/20/19, Brad Gilbert <b2gi...@gmail.com> wrote: > > Assuming it is a text file, it would be `.comb(512)` > > > > On Sun, Oct 20, 2019 at 4:39 PM Joseph Brenner <doom...@gmail.com> wrote: > > > >> I was just thinking about the case of processing a large file in > >> chunks of an arbitrary size (where "lines" or "words" don't really > >> work). I can think of a few approaches that would seem kind-of > >> rakuish, but don't seem to be built-in anywhere... something like a > >> variant of "slurp" with an argument to specify how much you want to > >> slurp at a time, that'll move on to the next chunk the next time it's > >> invoked... > >> > >> Is there anything like that kicking around that I've missed? > >> > >