示例#1
0
        public ZipBuilder AddBytes(byte[] bytes, string entryName)
        {
            ZipStream.PutNextEntry(CreateEntry(entryName));

            ZipStream.Write(bytes, 0, bytes.Length);

            ZipStream.CloseEntry();
            return(this);
        }
示例#2
0
        public ZipBuilder AddFile(string sourcePath, string entryName)
        {
            ZipStream.PutNextEntry(CreateEntry(entryName));

            StreamUtils.Copy(
                new FileStream(sourcePath, FileMode.Open, FileAccess.Read),
                ZipStream, new byte[4096]);

            ZipStream.CloseEntry();
            return(this);
        }
示例#3
0
        public ZipBuilder AddTextContent(string content, string entryName)
        {
            ZipStream.PutNextEntry(CreateEntry(entryName));

            // write directly to the ZipStream, but be sure to leave it open!
            using (var streamWriter = new StreamWriter(ZipStream, Encoding.UTF8, 4096, leaveOpen: true))
                streamWriter.Write(content);

            ZipStream.CloseEntry();

            return(this);
        }
示例#4
0
        public void Add(string fileName, Stream fileStream)
        {
            //create a new zip entry
            ZipEntry entry = factory.MakeFileEntry(fileName);

            entry.DateTime = DateTime.Now;
            ZipStream.PutNextEntry(entry);

            byte[] buffer = new byte[65536];

            int sourceBytes;

            do
            {
                sourceBytes = fileStream.Read(buffer, 0, buffer.Length);
                ZipStream.Write(buffer, 0, sourceBytes);
            }while (sourceBytes > 0);
        }
示例#5
0
        public void AddDirectory(string directoryName)
        {
            ZipEntry entry = factory.MakeDirectoryEntry(directoryName);

            ZipStream.PutNextEntry(entry);
        }