Example #1
0
        public static IOMode ParseIOMode(RubyFileMode mode, out bool preserveEndOfLines)
        {
            preserveEndOfLines = ((mode & RubyFileMode.BINARY) != 0);

            IOMode       io;
            RubyFileMode readWriteMode = mode & RubyFileMode.ReadWriteMask;

            if (readWriteMode == RubyFileMode.WRONLY)
            {
                io = ((mode & RubyFileMode.APPEND) != 0) ? IOMode.WriteOnlyAppend : IOMode.WriteOnlyTruncate;
            }
            else if (readWriteMode == RubyFileMode.RDONLY)
            {
                io = ((mode & RubyFileMode.APPEND) != 0) ? IOMode.ReadWriteFromStart : IOMode.ReadOnlyFromStart;
            }
            else if (readWriteMode == RubyFileMode.RDWR)
            {
                io = ((mode & RubyFileMode.APPEND) != 0) ? IOMode.ReadWriteAppend : IOMode.ReadWriteFromStart;
            }
            else
            {
                throw new ArgumentException("file mode must be one of WRONLY, RDONLY, RDWR");
            }

            return(io);
        }
Example #2
0
        private static Stream/*!*/ OpenFileStream(RubyContext/*!*/ context, string/*!*/ path, RubyFileMode mode) {
            FileMode fileMode;
            FileAccess access = FileAccess.Read;
            FileShare share = FileShare.ReadWrite;

            RubyFileMode readWriteFlags = mode & RubyFileMode.ReadWriteMask;

            if (readWriteFlags == RubyFileMode.WRONLY) {
                access = FileAccess.Write;
            } else if (readWriteFlags == RubyFileMode.RDONLY) {
                access = FileAccess.Read;
            } else if (readWriteFlags == RubyFileMode.RDWR) {
                access = FileAccess.ReadWrite;
            } else {
                throw new ArgumentException("file open mode must be one of RDONLY WRONLY or RDWR");
            }

            if ((mode & RubyFileMode.APPEND) != 0) {
                fileMode = FileMode.Append;
            } else if ((mode & RubyFileMode.CREAT) != 0) {
                fileMode = FileMode.Create;
            } else if ((mode & RubyFileMode.TRUNC) != 0) {
                fileMode = FileMode.Truncate;
            } else {
                fileMode = FileMode.Open;
            }

            if ((mode & RubyFileMode.EXCL) != 0) {
                share = FileShare.None;
            }

            return context.DomainManager.Platform.OpenInputFileStream(path, fileMode, access, share);
        }
Example #3
0
        public RubyIO(RubyContext /*!*/ context, Stream /*!*/ stream, RubyFileMode mode)
            : this(context) {
            ContractUtils.RequiresNotNull(stream, "stream");

            _mode   = ParseIOMode(mode, out _preserveEndOfLines);
            _stream = stream;

            ResetLineNumbersForReadOnlyFiles(context);
        }
Example #4
0
        private static Stream /*!*/ OpenFileStream(RubyContext /*!*/ context, string /*!*/ path, RubyFileMode mode)
        {
            FileMode   fileMode;
            FileAccess access = FileAccess.Read;
            FileShare  share  = FileShare.ReadWrite;

            RubyFileMode readWriteFlags = mode & RubyFileMode.ReadWriteMask;

            if (readWriteFlags == RubyFileMode.WRONLY)
            {
                access = FileAccess.Write;
            }
            else if (readWriteFlags == RubyFileMode.RDONLY)
            {
                access = FileAccess.Read;
            }
            else if (readWriteFlags == RubyFileMode.RDWR)
            {
                access = FileAccess.ReadWrite;
            }
            else
            {
                throw new ArgumentException("file open mode must be one of RDONLY WRONLY or RDWR");
            }

            if ((mode & RubyFileMode.APPEND) != 0)
            {
                fileMode = FileMode.Append;
            }
            else if ((mode & RubyFileMode.CREAT) != 0)
            {
                fileMode = FileMode.Create;
            }
            else if ((mode & RubyFileMode.TRUNC) != 0)
            {
                fileMode = FileMode.Truncate;
            }
            else
            {
                fileMode = FileMode.Open;
            }

            if ((mode & RubyFileMode.EXCL) != 0)
            {
                share = FileShare.None;
            }

            return(context.DomainManager.Platform.OpenInputFileStream(path, fileMode, access, share));
        }
Example #5
0
        public RubyIO(RubyContext/*!*/ context, Stream/*!*/ stream, RubyFileMode mode)
            : this(context) {
            ContractUtils.RequiresNotNull(stream, "stream");

            _mode = ParseIOMode(mode, out _preserveEndOfLines);
            _stream = stream;

            ResetLineNumbersForReadOnlyFiles(context);
        }
Example #6
0
        public static IOMode ParseIOMode(RubyFileMode mode, out bool preserveEndOfLines) {
            preserveEndOfLines = ((mode & RubyFileMode.BINARY) != 0);

            IOMode io;
            RubyFileMode readWriteMode = mode & RubyFileMode.ReadWriteMask;

            if (readWriteMode == RubyFileMode.WRONLY) {
                io = ((mode & RubyFileMode.APPEND) != 0) ? IOMode.WriteOnlyAppend : IOMode.WriteOnlyTruncate;
            } else if (readWriteMode == RubyFileMode.RDONLY) {
                io = ((mode & RubyFileMode.APPEND) != 0) ? IOMode.ReadWriteFromStart : IOMode.ReadOnlyFromStart;
            } else if (readWriteMode == RubyFileMode.RDWR) {
                io = ((mode & RubyFileMode.APPEND) != 0) ? IOMode.ReadWriteAppend : IOMode.ReadWriteFromStart;
            } else {
                throw new ArgumentException("file mode must be one of WRONLY, RDONLY, RDWR");
            }

            return io;
        }
Example #7
0
 public RubyFile(RubyContext /*!*/ context, string /*!*/ path, RubyFileMode mode)
     : base(context, OpenFileStream(context, path, mode), mode)
 {
     _path = path;
 }
Example #8
0
 public RubyFile(RubyContext/*!*/ context, string/*!*/ path, RubyFileMode mode)
     : base(context, OpenFileStream(context, path, mode), mode) {
     _path = path;
 }