public static Stream CreateBlubbZip(string Password, string[] FileNames, Stream[] Entrys)
        {
            Stream SaveStream = new MemoryStream();

            using (BlubbZipOutputStream outputStream = new BlubbZipOutputStream(SaveStream)) {
                try {
                    outputStream.Password = Password;
                    outputStream.SetLevel(9);

                    for (int i = 0; i < Entrys.Length; i++)
                    {
                        ZipStream("", FileNames[i], Entrys[i], outputStream);
                    }
                } catch (Exception e) {
                    System.Diagnostics.Debug.WriteLine(e);
                } finally {
                    if (outputStream != null)
                    {
                        outputStream.Finish();                         // don't close, will close also underlying Stream!
                    }
                }
            }

            return(SaveStream);
        }
Beispiel #2
0
        public static MemoryStream CreateBlubbZip(string blubbzipPassword, string[] contentFilenames, Stream[] contentData)
        {
            MemoryStream saveStream = new MemoryStream();

            using (MemoryStream tempStream = new MemoryStream()) {
                using (BlubbZipOutputStream outputStream = new BlubbZipOutputStream(tempStream)) {
                    try {
                        outputStream.Password = blubbzipPassword;
                        outputStream.SetLevel(9);

                        for (int i = 0; i < contentData.Length; i++)
                        {
                            ZipStream("", contentFilenames[i], contentData[i], outputStream);
                        }
                    } catch (Exception e) {
                        System.Diagnostics.Debug.WriteLine(e);
                    } finally {
                        if (outputStream != null)
                        {
                            outputStream.Finish();                             // don't close, will close also underlying Stream!
                        }
                    }

                    tempStream.WriteTo(saveStream);
                }
            }

            return(saveStream);
        }
        private static void ZipFile(string sourceFolder, string fileName, BlubbZipOutputStream outputStream)
        {
            using (FileStream fileStream = File.OpenRead(fileName)) {
                ZipStream(sourceFolder, fileName, fileStream, outputStream);

                fileStream.Close();
            }
        }
        public static void ZipStream(string sourceFolder, string fileName, Stream streamData, BlubbZipOutputStream outputStream)
        {
            if (streamData.CanRead == false || streamData.CanSeek == false)
            {
                return;
            }

            byte[]        buffer = new byte[65535];
            int           readCount;
            BlubbZipEntry entry = new BlubbZipEntry(BlubbZipEntry.CleanName(GodLesZ.Library.BlubbZip.Tools.PatchKnownProblems(GodLesZ.Library.BlubbZip.Tools.MakePathRelative(sourceFolder, fileName))));

            streamData.Seek(0, SeekOrigin.Begin);

            entry.DateTime = DateTime.Now;
            entry.Size     = streamData.Length;

            outputStream.PutNextEntry(entry);
            mCrc.Reset();
            while ((readCount = streamData.Read(buffer, 0, buffer.Length)) > 0)
            {
                mCrc.Update(buffer, 0, readCount);
                outputStream.Write(buffer, 0, readCount);
            }

            entry.Crc = mCrc.Value;
        }