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 void Decompress(Stream source, Stream target) { var reader = new SwfStreamReader(source); var outputWriter = new SwfStreamWriter(target); var fileInfo = reader.ReadSwfFileInfo(); var rest = reader.ReadRest(); if (fileInfo.Format == "CWS") { var uncompressed = new MemoryStream(); SwfZip.Decompress(new MemoryStream(rest), uncompressed); outputWriter.WriteSwfFileInfo(new SwfFileInfo { Format = "FWS", FileLength = (uint)(uncompressed.Length), Version = fileInfo.Version }); outputWriter.WriteBytes(uncompressed.ToArray()); } else if (fileInfo.Format == "FWS") { outputWriter.WriteSwfFileInfo(fileInfo); outputWriter.WriteBytes(rest); } else { throw new NotSupportedException("Illegal file format"); } outputWriter.Flush(); }
public static SwfFile ReadFrom(Stream stream) { var file = new SwfFile(); ISwfStreamReader reader = new SwfStreamReader(stream); file.FileInfo = reader.ReadSwfFileInfo(); reader = GetSwfStreamReader(file.FileInfo, stream); file.Header = reader.ReadSwfHeader(); ReadTags(file, reader); return file; }
public static SwfFile ReadFrom(Stream stream) { var file = new SwfFile(); ISwfStreamReader reader = new SwfStreamReader(stream); file.FileInfo = reader.ReadSwfFileInfo(); reader = GetSwfStreamReader(file.FileInfo, stream); file.Header = reader.ReadSwfHeader(); ReadTags(file, reader); return(file); }
public static void Compress(Stream source, Stream target) { var reader = new SwfStreamReader(source); var outputWriter = new SwfStreamWriter(target); var fileInfo = reader.ReadSwfFileInfo(); var rest = reader.ReadRest(); if (fileInfo.Format == "FWS") { var compressed = new MemoryStream(); SwfZip.Compress(new MemoryStream(rest), compressed); outputWriter.WriteSwfFileInfo(new SwfFileInfo { Format = "CWS", FileLength = (uint)(rest.Length) + 8, Version = fileInfo.Version }); outputWriter.WriteBytes(compressed.ToArray()); } else { outputWriter.WriteSwfFileInfo(fileInfo); outputWriter.WriteBytes(rest); } outputWriter.Flush(); }