Tạo kho lưu trữ để lưu trữ các tập tin, một hoặc nhiều tập tin
Đơn giản hóa việc quản lý tệp bằng công cụ lưu trữ .NET
Tổng quan
Cách ZIP nhiều tập tin
Mặc định là thuật toán Deflate
Zip compression with Deflate algoritm
using (Archive archive = new Archive())
{
archive.CreateEntry("first.bin", "data1.bin");
archive.CreateEntry("second.bin", "data2.bin");
// Add as many entries as you need
archive.Save("archive.zip");
}
Cách tạo kho lưu trữ 7-ZIP của một số tệp
Mặc định cho 7-zip là thuật toán LZMA
7-Zip with LZMA algorithm
using (SevenZipArchive archive = new SevenZipArchive())
{
archive.CreateEntry("first.bin", "data1.bin");
archive.CreateEntry("second.bin", "data2.bin");
// Add as many entries as you need
archive.Save("archive.7z");
}
Lưu trữ XAR với một số tệp
Mặc định là thuật toán ZLib
XAR with ZLib algorithm
using (XarArchive archive = new XarArchive())
{
archive.CreateEntry("first.bin", "data1.bin");
archive.CreateEntry("second.bin", "data2.bin");
// Add as many entries as you need
archive.Save("archive.xar");
}
Lưu trữ nhiều tập tin mà không cần nén
Cách tiếp cận các định dạng TAR và CPIO tương tự nhau và nằm trong phương thức CreateEntry đã biết.
Lưu trữ TAR không nén
TAR storing files without compression
using (TarArchive archive = new TarArchive())
{
archive.CreateEntry("first.bin", "data1.bin");
archive.CreateEntry("second.bin", "data2.bin");
// Add as many entries as you need
archive.Save("archive.tar");
}
Lưu trữ CPIO không nén
CPIO storing files without compression
using (TarArchive archive = new TarArchive())
{
archive.CreateEntry("first.bin", "data1.bin");
archive.CreateEntry("second.bin", "data2.bin");
// Add as many entries as you need
archive.Save("archive.cpio");
}
Các định dạng chỉ nén không có mục nhập
Các kho lưu trữ như GZIP, LZ, BZIP2, XX, Z không hỗ trợ các mục và chỉ có thể nén một nguồn duy nhất. Xem các mẫu có độ nén như vậy.
Lưu trữ GZ Các định dạng chỉ nén không có mục nhập
GZIP with compress only single source
using (FileStream source = File.Open("alice29.txt", FileMode.Open, FileAccess.Read))
{
using (GzipArchive archive = new GzipArchive())
{
archive.SetSource(source);
archive.Save("archive.gz");
}
}
LZ archive Các định dạng chỉ nén không có mục nhập
LZIP with compress only single source
using (FileStream source = File.Open("alice29.txt", FileMode.Open, FileAccess.Read))
{
using (GzipArchive archive = new GzipArchive())
{
archive.SetSource(source);
archive.Save("archive.gz");
}
}
Aspose.ZIP cho phép kết hợp các định dạng chỉ lưu trữ và chỉ nén bằng một phương thức duy nhất. Dưới đây là ví dụ về chức năng này với sự kết hợp TAR.GZ. Để đạt được điều này, chúng tôi sử dụng phương pháp SaveGzipped.
Sự kết hợp TAR.GZ
Có các phương pháp tương tự cho các định dạng nén LZIP, XX, ZStandard, Z.
TAR.GZ with SaveGzipped method
using (TarArchive archive = new TarArchive())
{
archive.CreateEntry("first.bin", "data1.bin");
archive.CreateEntry("second.bin", "data2.bin");
archive.SaveGzipped("archive.tar.gz");
}
TAR.BZ2
Tuy nhiên chúng ta cần sử dụng cách tiếp cận khác cho định dạng BZIP2.
BZIP2 with SaveGzipped method
using (TarArchive tar = new TarArchive())
{
tar.CreateEntry("first.bin", "data1.bin");
tar.CreateEntry("second.bin", "data2.bin");
using (Bzip2Archive archive = new Bzip2Archive())
{
archive.SetSource(tar);
archive.Save("archive.tar.bz2");
}
}
Các tính năng Aspose.ZIP được hỗ trợ khác cho .NET API
Sử dụng thư viện Aspose.ZIP C# để chuyển đổi, hợp nhất, chỉnh sửa tài liệu tệp zip, trích xuất dữ liệu từ kho lưu trữ và hơn thế nữa!
Support and Learning Resources
- Learning Resources
- Documentation
- Source Code
- API References
- Tutorial Videos
- Product Support
- Free Support
- Paid Support
- Blog
- Release Notes
- Why Aspose.ZIP for .NET?
- Customers List
- Success Stories