Example #1
0
        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);
        }
Example #2
0
        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);
        }