Exemplo n.º 1
0
        /// <summary>
        /// Create a new instance of the <see cref="GodotFileStream"/> class.
        /// </summary>
        /// <param name="path">The path to the file to open. This accepts Godot-style <code>user://</code> and <code>res://</code> paths.</param>
        /// <param name="flags">File flags.</param>
        /// <param name="compressionMode">If not null, this will enable compression/decompression.</param>
        public GodotFileStream(string path, File.ModeFlags flags, File.CompressionMode?compressionMode = null)
        {
            if (path == null)
            {
                throw new ArgumentNullException("path");
            }

            _file  = new File();
            _flags = flags;
            Error result;

            if (compressionMode.HasValue)
            {
                result = _file.OpenCompressed(path, flags, compressionMode.Value);
            }
            else
            {
                result = _file.Open(path, flags);
            }

            if (result != Error.Ok)
            {
                throw new IOException($"Unable to open \"{path}\": {result}");
            }
        }