GetReadableStream() public method

public GetReadableStream ( ) : RubyBufferedStream
return RubyBufferedStream
Ejemplo n.º 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));
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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;
 }
Ejemplo n.º 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;
        }
Ejemplo n.º 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);
        }