MakeReader() абстрактный публичный Метод

abstract public MakeReader ( ) : BinaryReader
Результат System.IO.BinaryReader
Пример #1
0
        public PackagedFileInfo WriteFile(FileInfo info)
        {
            // Assume that all files are written uncompressed (worst-case) when calculating package sizes
            var size = info.Size();

            if (streams.Last().Position + size > MaxPackageSize)
            {
                // Start a new package file if the current one is full.
                var partPath = Package.MakePartFilename(path, streams.Count);
                var nextPart = new FileStream(partPath, FileMode.Create, FileAccess.Write);
                streams.Add(nextPart);
            }

            var stream   = streams.Last();
            var packaged = new PackagedFileInfo();

            packaged.PackageStream    = stream;
            packaged.Name             = info.Name;
            packaged.UncompressedSize = size;
            packaged.ArchivePart      = (UInt32)(streams.Count - 1);
            packaged.OffsetInFile     = (UInt32)stream.Position;
            packaged.Flags            = BinUtils.MakeCompressionFlags(Compression, CompressionLevel);

            var reader       = info.MakeReader();
            var uncompressed = reader.ReadBytes((int)reader.BaseStream.Length);
            var compressed   = BinUtils.Compress(uncompressed, Compression, CompressionLevel);

            stream.Write(compressed, 0, compressed.Length);
            reader.Dispose();

            packaged.SizeOnDisk = (UInt32)(stream.Position - packaged.OffsetInFile);
            packaged.Crc        = Crc32.Compute(compressed);

            var padLength = PaddingLength();

            if (stream.Position % padLength > 0)
            {
                // Pad the file to a multiple of 64 bytes
                byte[] pad = new byte[padLength - (stream.Position % padLength)];
                for (int i = 0; i < pad.Length; i++)
                {
                    pad[i] = 0xAD;
                }

                stream.Write(pad, 0, pad.Length);
            }

            return(packaged);
        }
Пример #2
0
        public PackagedFileInfo WriteFile(FileInfo info)
        {
            // Assume that all files are written uncompressed (worst-case) when calculating package sizes
            var size = info.Size();
            if (streams.Last().Position + size > MaxPackageSize)
            {
                // Start a new package file if the current one is full.
                var partPath = Package.MakePartFilename(path, streams.Count);
                var nextPart = new FileStream(partPath, FileMode.Create, FileAccess.Write);
                streams.Add(nextPart);
            }

            var stream = streams.Last();
            var packaged = new PackagedFileInfo();
            packaged.PackageStream = stream;
            packaged.Name = info.Name;
            packaged.UncompressedSize = size;
            packaged.ArchivePart = (UInt32)(streams.Count - 1);
            packaged.OffsetInFile = (UInt32)stream.Position;
            packaged.Flags = BinUtils.MakeCompressionFlags(Compression, CompressionLevel);

            var reader = info.MakeReader();
            var uncompressed = reader.ReadBytes((int)reader.BaseStream.Length);
            var compressed = BinUtils.Compress(uncompressed, Compression, CompressionLevel);
            stream.Write(compressed, 0, compressed.Length);
            reader.Dispose();

            packaged.SizeOnDisk = (UInt32)(stream.Position - packaged.OffsetInFile);
            packaged.Crc = Crc32.Compute(compressed);

            var padLength = PaddingLength();
            if (stream.Position % padLength > 0)
            {
                // Pad the file to a multiple of 64 bytes
                byte[] pad = new byte[padLength - (stream.Position % padLength)];
                for (int i = 0; i < pad.Length; i++)
                {
                    pad[i] = 0xAD;
                }

                stream.Write(pad, 0, pad.Length);
            }

            return packaged;
        }