Exemplo n.º 1
0
        private static Stream /*!*/ OpenFileStream(RubyContext /*!*/ context, string /*!*/ path, string /*!*/ modeString)
        {
            FileMode   mode;
            FileAccess access;

            // ignore "b":
            bool preserveEndOfLines;

            switch (RubyIO.ParseIOMode(modeString, out preserveEndOfLines))
            {
            case IOMode.ReadOnlyFromStart:
                mode = FileMode.Open; access = FileAccess.Read;
                break;

            case IOMode.ReadWriteFromStart:
                mode = FileMode.Open; access = FileAccess.ReadWrite;
                break;

            case IOMode.WriteOnlyTruncate:
                mode = FileMode.Create; access = FileAccess.Write;
                break;

            case IOMode.ReadWriteTruncate:
                mode = FileMode.Create; access = FileAccess.ReadWrite;
                break;

            case IOMode.WriteOnlyAppend:
                mode = FileMode.Append; access = FileAccess.Write;
                break;

            case IOMode.ReadWriteAppend:
                mode = FileMode.Append; access = FileAccess.ReadWrite;
                break;

            default:
                throw RubyIO.IllegalMode(modeString);
            }
            return(context.DomainManager.Platform.OpenInputFileStream(path, mode, access, FileShare.ReadWrite));
        }