System.IO.Packaging.Package.OpenCore C# (CSharp) Méthode

OpenCore() private static méthode

private static OpenCore ( Stream stream, FileMode packageMode, FileAccess packageAccess, bool ownsStream ) : Package
stream Stream
packageMode FileMode
packageAccess FileAccess
ownsStream bool
Résultat Package
        private static Package OpenCore(Stream stream, FileMode packageMode, FileAccess packageAccess, bool ownsStream)
        {
            if ((packageAccess & FileAccess.Read) == FileAccess.Read && !stream.CanRead)
                throw new IOException("Stream does not support reading");

            if ((packageAccess & FileAccess.Write) == FileAccess.Write && !stream.CanWrite)
                throw new IOException("Stream does not support reading");

            if (!stream.CanSeek)
                throw new ArgumentException("stream", "Stream must support seeking");

            if (packageMode == FileMode.Open && stream.Length == 0)
                throw new FileFormatException("Stream length cannot be zero with FileMode.Open");

            if (packageMode == FileMode.CreateNew && stream.Length > 0)
                throw new IOException("Cannot use CreateNew when stream contains data");

            if (packageMode == FileMode.Append || packageMode == FileMode.Truncate)
            {
                if (stream.CanWrite)
                    throw new NotSupportedException(string.Format("PackageMode.{0} is not supported", packageMode));
                else
                    throw new IOException(string.Format("PackageMode.{0} is not supported", packageMode));
            }

            return new ZipPackage(packageAccess, ownsStream, stream);
        }