Beispiel #1
0
        public override ImageData Read(IBinaryStream stream, ImageMetaData info)
        {
            var meta = (ApsMetaData)info;

            stream.Position = meta.DataOffset;
            byte[] image_data;
            if (meta.IsPacked)
            {
                using (var reader = new LzReader(stream.AsStream, meta.PackedSize, meta.UnpackedSize))
                {
                    reader.Unpack();
                    image_data = reader.Data;
                }
            }
            else
            {
                image_data = stream.ReadBytes((int)meta.UnpackedSize);
            }
            using (var unpacked = BinaryStream.FromArray(image_data, stream.Name))
            {
                var ap_info = base.ReadMetaData(unpacked);
                if (null == ap_info)
                {
                    throw new InvalidFormatException();
                }
                return(base.Read(unpacked, ap_info));
            }
        }
Beispiel #2
0
        public override Stream OpenEntry(ArcFile arc, Entry entry)
        {
            var packed_entry = entry as PackedEntry;

            if (null == packed_entry || !packed_entry.IsPacked)
            {
                return(arc.File.CreateStream(entry.Offset, entry.Size));
            }
            if (0 == packed_entry.UnpackedSize)
            {
                packed_entry.UnpackedSize = arc.File.View.ReadUInt32(entry.Offset - 4);
            }
            using (var input = arc.File.CreateStream(entry.Offset, entry.Size))
                using (var reader = new LzReader(input, entry.Size, packed_entry.UnpackedSize))
                {
                    reader.Unpack();
                    return(new BinMemoryStream(reader.Data, entry.Name));
                }
        }