private int ReadBuffer(byte[] buffer, int ib, int len) { var b = bgReader.ReadBlock(); // for the gzip case, the main thread should do the line breaking if (offsets.Count != 0) { LineBreaker.ComputeLineAndFieldOffsets(b); } int cb = b.cb; posNext = b.position; if (b.cb > 0) { Array.Copy(b.buffer, 0, buffer, ib, b.cb); Array.Copy(b.offsets, 0, stm_offsets, 0, b.cFields); stm_c_offsets = b.cFields; stm_i_offset = 0; } bgReader.Free(b); return(cb); }
private void ProcessAndTransfer(Block b, int cbBuffer) { if (cbBuffer > 0) { byte[] buffer = b.buffer; int ibLastNewline = cbBuffer - 1; while (buffer[ibLastNewline] != '\n' && ibLastNewline > 0) { ibLastNewline--; } int ibCopy = ibLastNewline + 1; int ib = 0; while (ibCopy < cbBuffer) { bufferScratch[ib++] = buffer[ibCopy++]; } cbScratch = ib; b.position = (((long)currentSegment) << 32) + currentSegmentOffset; b.cb = ibLastNewline + 1; currentSegmentOffset += b.cb; // for the non-gzip case, the background thread should do the line breaking if (offsets.Count == 0) { LineBreaker.ComputeLineAndFieldOffsets(b); } } else { b.position = -1; b.cb = 0; b.offsets[0] = 0; } lock (blocksReady) { blocksReady.AddLast(b); } semaphoreFromBg.Release(1); }