Example #1
0
        static void Main(string[] args)
        {
            if (args == null || args.Length != 2)
                Console.WriteLine("Usage: <source folder> <destinaion file>");

            var source = new DirectoryInfo(args[0]);

            if (!source.Exists)
                throw new ApplicationException("Source folder does not exist");

            var destination = new FileInfo(args[1]);
            if (destination.Exists)
                throw new ApplicationException("Destination already exists");

            // mem-stream needs to be here for this to work?
            using (var destinationStream = destination.OpenWrite())
            using (var memStream = new MemoryStream())
            using (var lz4Stream = new LZ4Stream(destinationStream, CompressionMode.Compress, true, true))
            {
                using (var zipArchive = new ZipArchive(memStream, ZipArchiveMode.Create, true))

                    AddFilesToArchive(source, "", zipArchive);

                memStream.Position = 0;
                memStream.CopyTo(lz4Stream);
            }
        }
        private void ExtractEmbeddedLz4Stream(string name, DirectoryInfo destination)
        {
            var started = Stopwatch.StartNew();

            using (var stream = GetType().Assembly.GetManifestResourceStream(typeof(RessourceTarget), name))
            using (var decompresStream = new LZ4Stream(stream, CompressionMode.Decompress))
            using (var archiveReader = new ArchiveReader(decompresStream))
                archiveReader.ExtractToDirectory(destination);

            Info("Extracted {0} in {1} seconds", name, started.Elapsed.TotalSeconds);
        }