Beispiel #1
0
        public override int ReadByte()
        {
            if (!CanRead)
            {
                throw new NotSupportedException("The stream does not support reading");
            }

            byte[] buffer = new byte[1];
            ulong  bytesRead;
            Result result;

            if (async)
            {
                Async.Read(handle, out buffer[0], 1, readCallback);
                Wait();
                result = asyncResult;
            }
            else
            {
                result = Sync.Read(handle, out buffer[0], 1UL, out bytesRead);
            }
            if (result == Result.ErrorEof)
            {
                return(-1);
            }

            Vfs.ThrowException(Uri, result);
            return(buffer[0]);
        }
Beispiel #2
0
        public override int Read(byte[] buffer, int offset, int count)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException("buffer");
            }
            else if (offset < 0)
            {
                throw new ArgumentOutOfRangeException("offset", "Must be >= 0");
            }
            else if (count < 0)
            {
                throw new ArgumentOutOfRangeException("count", "Must be >= 0");
            }
            else if (count > buffer.Length - offset)
            {
                throw new ArgumentException("Buffer too small, count/offset wrong");
            }
            else if (!CanRead)
            {
                throw new NotSupportedException("The stream does not support reading");
            }

            ulong  bytesRead;
            Result result;

            if (async)
            {
                Async.Read(handle, out buffer[offset], (uint)count, readCallback);
                Wait();
                result    = asyncResult;
                bytesRead = asyncBytesRead;
            }
            else
            {
                result = Sync.Read(handle, out buffer[offset], (ulong)count, out bytesRead);
            }
            if (result == Result.ErrorEof)
            {
                return(0);
            }

            Vfs.ThrowException(Uri, result);
            return((int)bytesRead);
        }