···144144145145 // initialize the read buffer
146146 var buf: [1024]u8 = undefined;
147147+ var read_start: usize = 0;
147148 // read loop
148149 while (!self.should_quit) {
149149- const n = try posix.read(self.fd, &buf);
150150+ const n = try posix.read(self.fd, buf[read_start..]);
150151 var start: usize = 0;
151152 while (start < n) {
152153 const result = try parser.parse(buf[start..n], paste_allocator);
154154+ if (result.n == 0) {
155155+ // copy the read to the beginning. We don't use memcpy because
156156+ // this could be overlapping, and it's also rare
157157+ const initial_start = start;
158158+ while (start < n) : (start += 1) {
159159+ buf[start - initial_start] = buf[start];
160160+ }
161161+ read_start = start - initial_start + 1;
162162+ continue;
163163+ }
164164+ read_start = 0;
153165 start += result.n;
154166 // TODO: if we get 0 byte read, copy the remaining bytes to the
155167 // beginning of the buffer and read mmore? this should only happen