public static long readstream(Stream fs, rqueue q, int maxblksz) { long ret = fs.Length; byte[] buffer = null; BinaryReader binReader = new BinaryReader(fs); long left = fs.Length; try { while (left > 0) { long size = Math.Min(maxblksz, left); buffer = binReader.ReadBytes((int)size); while (!q.has_stopped() && q.produce(buffer) == 0) { ; } if (q.has_stopped()) { break; } left -= size; } } catch (Exception) { } binReader.Close(); //fs.Close(); // binReader disposed? q.stop(); return(ret - left); }
public static long writestream(Stream output, rqueue q, string filename) { long ret = 0; byte[] buffer; try { while (true) { if ((buffer = q.consume()) != null) { output.Write(buffer, 0, buffer.Length); } else if (q.has_stopped()) { break; } if (buffer != null) { ret += buffer.Length; } } } catch (Exception) { } output.Close(); return(ret); }
public static void writestream_log(Stream output, rqueue q, string filename, Action <string> log) { int starttm = Environment.TickCount; long size = writestream(output, q, filename); int deltatm = Math.Max(1, (Environment.TickCount - starttm) / 1000); log("I: Write file " + filename + ", size " + size.ToString("###,###") + " bytes, time " + deltatm + " s; " + (size / deltatm).ToString("###,###.0") + " Bps; "); }
public static void readstream_log(Stream fs, rqueue q, int maxblksz, string filename, Action <string> log) { int starttm = Environment.TickCount; long size = readstream(fs, q, maxblksz); int deltatm = Math.Max(1, (Environment.TickCount - starttm) / 1000); log("I: Read file " + filename + ", size " + size.ToString("###,###") + " bytes, time " + deltatm + " s; " + (size / deltatm).ToString("###,###.0") + " Bps; "); }