public static void Compress(Stream source, Stream target, SwfFormat compressionFormat) { var reader = new SwfStreamReader(source); var outputWriter = new SwfStreamWriter(target); var fileInfo = reader.ReadSwfFileInfo(); var rest = reader.ReadRest(); if (fileInfo.Format != SwfFormat.FWS) { MemoryStream mem = new MemoryStream(); source.Seek(0, SeekOrigin.Begin); Decompress(source, mem); mem.Seek(0, SeekOrigin.Begin); reader = new SwfStreamReader(mem); fileInfo = reader.ReadSwfFileInfo(); rest = reader.ReadRest(); } outputWriter.WriteSwfFileInfo(new SwfFileInfo { Format = compressionFormat, FileLength = (uint)(rest.Length) + 8, Version = fileInfo.Version }); var compressed = new MemoryStream(); SwfZip.Compress(new MemoryStream(rest), compressed, compressionFormat); outputWriter.WriteBytes(compressed.ToArray()); outputWriter.Flush(); }
public static void Decompress(Stream source, Stream target) { var reader = new SwfStreamReader(source); var outputWriter = new SwfStreamWriter(target); var fileInfo = reader.ReadSwfFileInfo(); if (fileInfo.Format == SwfFormat.Unknown) { throw new NotSupportedException("Illegal file format"); } var rest = reader.ReadRest(); if (fileInfo.Format == SwfFormat.FWS) { outputWriter.WriteSwfFileInfo(fileInfo); outputWriter.WriteBytes(rest); return; } var uncompressed = new MemoryStream(); SwfZip.Decompress(new MemoryStream(rest), uncompressed, fileInfo.Format); outputWriter.WriteSwfFileInfo(new SwfFileInfo { Format = SwfFormat.FWS, FileLength = (uint)(uncompressed.Length + 8), Version = fileInfo.Version }); outputWriter.WriteBytes(uncompressed.ToArray()); outputWriter.Flush(); }
public static ISwfStreamReader GetSwfStreamReader(SwfFileInfo info, Stream stream) { if (info.Format == SwfFormat.FWS) { return(new SwfStreamReader(stream)); } MemoryStream memoryStream = new MemoryStream(); SwfZip.Decompress(stream, memoryStream, info.Format); return(new SwfStreamReader(memoryStream)); }