Thanks, this looks great On Friday, August 4, 2017 at 10:34:41 AM UTC-6, rog wrote: > > Ah, and I just found another version, somewhat simpler, > that just reads bytes in reverse: > > https://play.golang.org/p/mYsP7iHmiW > > > On 4 August 2017 at 16:43, roger peppe <rogp...@gmail.com <javascript:>> > wrote: > > I wrote this code a while ago to accomplish a similar task > > (actually I wanted to scan lines in reverse, but it works > > for bytes too, because it works with bufio.ScanBytes): > > > > https://play.golang.org/p/dqmlmdqk9k > > > > If you were going to use it in production, it would > > need lots of tests - it may well be wrong! Also, I've > > no idea what its performance characteristics are - I'm > > sure it would not be hard to make a reverse byte reader > > optimised for that purpose that was considerably > > more efficient. > > > > Hope this helps, > > > > rog. > > > > > > On 4 August 2017 at 16:01, <zack....@gmail.com <javascript:>> wrote: > >> I'm working on a finite state machine that processes a file byte by > byte, > >> without loading the entire file into memory. Currently it works in the > >> forward direction, but I'd like to get it working in the reverse > direction > >> as well. Currently I make a *bufio.Readerfrom a open file / response > body > >> and then use ReadByte() to get each byte from beginning to end. > >> > >> > >> I'm wondering, what is the best way to get each byte starting from the > end > >> and going to the beginning? My first idea to read backwards is to use a > >> combination of UnreadByte() and Peek(1) to read in reverse after > advancing > >> the reader to the end. I'd like to avoid reading in the whole file into > >> memory. > >> > >> -- > >> You received this message because you are subscribed to the Google > Groups > >> "golang-nuts" group. > >> To unsubscribe from this group and stop receiving emails from it, send > an > >> email to golang-nuts...@googlegroups.com <javascript:>. > >> For more options, visit https://groups.google.com/d/optout. >
-- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.