Ejemplo n.º 1
0
        /// <summary>
        /// Reads a file structure from an open stream.
        /// </summary>
        /// <param name="stream">Stream to read from.</param>
        /// <returns>File structure populated from the stream.</returns>
        public static FileStructure Read(Stream stream)
        {
            FileStructure fs = new FileStructure();

            using (NonClosingStreamWrapper wrapper = new NonClosingStreamWrapper(stream))
                using (BinaryReader reader = new BinaryReader(wrapper))
                {
                    fs.FileFormat = FileStructure.ReadFileFormat(reader);

                    if (FileFormat.Unknown != fs.FileFormat)
                    {
                        fs.embeddedFileSizes = FileStructure.ReadEmbeddedFileSizes(reader);

                        // Remember the data stream offset, which is right after the embedded files have been written.
                        fs.dataStreamOffset = stream.Position;
                        foreach (long size in fs.embeddedFileSizes)
                        {
                            fs.dataStreamOffset += size;
                        }
                    }
                }

            fs.stream = stream;

            return(fs);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Reads a file structure from an open stream.
        /// </summary>
        /// <param name="stream">Stream to read from.</param>
        /// <returns>File structure populated from the stream.</returns>
        public static FileStructure Read(Stream stream)
        {
            var fs = new FileStructure();

            using (var reader = new BinaryReader(stream, Encoding.UTF8, true))
            {
                fs.FileFormat = FileStructure.ReadFileFormat(reader);

                if (fs.FileFormat != FileFormat.Unknown)
                {
                    fs.embeddedFileSizes = FileStructure.ReadEmbeddedFileSizes(reader);

                    // Remember the data stream offset, which is right after the embedded files have been written.
                    fs.dataStreamOffset = stream.Position;
                    foreach (long size in fs.embeddedFileSizes)
                    {
                        fs.dataStreamOffset += size;
                    }
                }
            }

            fs.stream = stream;

            return(fs);
        }