GetReadableStream() public method

public GetReadableStream ( ) : RubyBufferedStream
return RubyBufferedStream
Beispiel #1
0
        public static MutableString /*!*/ ReadNoBlock(RubyIO /*!*/ self, [DefaultProtocol] int bytes, [DefaultProtocol, Optional] MutableString buffer)
        {
            var stream = self.GetReadableStream();

            try {
                stream.ReadTimeout = 0;
            } catch (InvalidOperationException) {
                throw RubyExceptions.CreateEBADF();
            }

            return(Read(self, bytes, buffer));
        }
Beispiel #2
0
        public static MutableString /*!*/ SystemRead(RubyIO /*!*/ self, [DefaultProtocol] int bytes, [DefaultProtocol, Optional] MutableString buffer)
        {
            var stream = self.GetReadableStream();

            if (stream.DataBuffered)
            {
                throw RubyExceptions.CreateIOError("sysread for buffered IO");
            }

            // We use Flush to simulate non-buffered IO.
            // A better approach would be to create a parallel FileStream with
            // System.IO.FileOptions.WriteThrough (which corresponds to FILE_FLAG_NO_BUFFERING), and also maybe
            // System.IO.FileOptions.SequentialScan (FILE_FLAG_SEQUENTIAL_SCAN).
            // TODO: sysopen does that?
            stream.Flush();

            var result = Read(self, bytes, buffer);

            if (result == null)
            {
                throw new EOFError("end of file reached");
            }
            return(result);
        }
Beispiel #3
0
 public static MutableString ReadNoBlock(RubyIO/*!*/ self, [DefaultProtocol]int bytes, [DefaultProtocol, Optional]MutableString buffer) {
     var stream = self.GetReadableStream();
     MutableString result = null;
     self.NonBlockingOperation(() => result = Read(self, bytes, buffer), true);
     return result;
 }
Beispiel #4
0
        public static MutableString/*!*/ SystemRead(RubyIO/*!*/ self, [DefaultProtocol]int bytes, [DefaultProtocol, Optional]MutableString buffer) {
            var stream = self.GetReadableStream();
            if (stream.DataBuffered) {
                throw RubyExceptions.CreateIOError("sysread for buffered IO");
            }

            // We use Flush to simulate non-buffered IO. 
            // A better approach would be to create a parallel FileStream with 
            // System.IO.FileOptions.WriteThrough (which corresponds to FILE_FLAG_NO_BUFFERING), and also maybe 
            // System.IO.FileOptions.SequentialScan (FILE_FLAG_SEQUENTIAL_SCAN).
            // TODO: sysopen does that?
            stream.Flush();

            var result = Read(self, bytes, buffer);
            if (result == null) {
                throw new EOFError("end of file reached");
            }
            return result;
        }
Beispiel #5
0
        public static MutableString/*!*/ ReadNoBlock(RubyIO/*!*/ self, [DefaultProtocol]int bytes, [DefaultProtocol, Optional]MutableString buffer) {
            var stream = self.GetReadableStream();

            try {
                stream.ReadTimeout = 0;
            } catch (InvalidOperationException) {
                throw RubyExceptions.CreateEBADF();
            }

            return Read(self, bytes, buffer);
        }