Exemplo n.º 1
0
        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();
        }
Exemplo n.º 2
0
        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();
        }