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); }
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); }
public RubyIO(RubyContext /*!*/ context, Stream /*!*/ stream, RubyFileMode mode) : this(context) { ContractUtils.RequiresNotNull(stream, "stream"); _mode = ParseIOMode(mode, out _preserveEndOfLines); _stream = stream; ResetLineNumbersForReadOnlyFiles(context); }
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)); }
public RubyIO(RubyContext/*!*/ context, Stream/*!*/ stream, RubyFileMode mode) : this(context) { ContractUtils.RequiresNotNull(stream, "stream"); _mode = ParseIOMode(mode, out _preserveEndOfLines); _stream = stream; ResetLineNumbersForReadOnlyFiles(context); }
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; }
public RubyFile(RubyContext /*!*/ context, string /*!*/ path, RubyFileMode mode) : base(context, OpenFileStream(context, path, mode), mode) { _path = path; }
public RubyFile(RubyContext/*!*/ context, string/*!*/ path, RubyFileMode mode) : base(context, OpenFileStream(context, path, mode), mode) { _path = path; }