GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — badio/break_reader.go at master · cavaliergopher/badio Expand file tree/ Copy pathbreak_reader.goMore file actions 44 lines (36 loc) · 829 Bytes / Copy pathbreak_reader.goFile metadata and controls44 lines (36 loc) · 829 Bytes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 package badio import ( "io" ) type breakReader struct { r io.Reader n int64 o int64 } // NewBreakReader returns a Reader that behaves like r except that it will // return a BadIOError (not io.EOF) once it has read n bytes. func NewBreakReader(r io.Reader, n int64) io.Reader { return &breakReader{r: r, n: n} } func (c *breakReader) Read(p []byte) (n int, err error) { // reduce read size if it exceeds the breakpoint n = len(p) if c.o+int64(n) > c.n { n = int(c.n - c.o) } // test if break point exceeded if n == 0 { return 0, newError("Reader is already broken at offset %d (0x%X)", c.o, c.o) } // read into buffer n, err = c.r.Read(p[0:n]) if err != nil { return } // break? c.o += int64(n) if c.o >= c.n { return n, newError("Reader break point at offset %d (0x%X)", c.o, c.o) } return } |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |