Class SevenZipArchiveEntry

Class SevenZipArchiveEntry

Namespace: Aspose.Zip.SevenZip
Assembly: Aspose.Zip.dll (25.1.0)

Đại diện cho một tệp đơn trong kho lưu trữ 7z.

public abstract class SevenZipArchiveEntry : IArchiveFileEntry

Kế thừa

objectSevenZipArchiveEntry

Kế thừa

SevenZipArchiveEntryEncrypted, SevenZipArchiveEntryPlain

Triển khai

IArchiveFileEntry

Thành viên kế thừa

object.GetType(), object.MemberwiseClone(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()

Nhận xét

Chuyển đổi một thể hiện của Aspose.Zip.SevenZip.SevenZipArchiveEntry sang Aspose.Zip.SevenZip.SevenZipArchiveEntryEncrypted để xác định xem mục có được mã hóa hay không.

Bộ xây dựng

SevenZipArchiveEntry(SevenZipArchive, string, SevenZipCompressionSettings, Stream, FileAttributes, FileSystemInfo)

Khởi tạo một thể hiện mới của lớp Aspose.Zip.SevenZip.SevenZipArchiveEntry.

protected SevenZipArchiveEntry(SevenZipArchive parent, string name, SevenZipCompressionSettings compressionSettings, Stream source, FileAttributes fileAttributes, FileSystemInfo fileInfo = null)

Tham số

parent SevenZipArchive

tên string

Tên mục.

compressionSettings SevenZipCompressionSettings

Cài đặt cho nén hoặc giải nén.

source Stream

Luồng chứa dữ liệu mục cần nén hoặc giải nén.

fileAttributes FileAttributes

Thuộc tính từ hệ thống tệp.

fileInfo FileSystemInfo

Thông tin tệp hoặc thư mục mà mục dựa trên.

Ngoại lệ

ArgumentException

name là null hoặc rỗng.

Thuộc tính

CompressedSize

Lấy kích thước của tệp đã nén.

public ulong CompressedSize { get; }

Giá trị thuộc tính

ulong

CompressionSettings

Lấy cài đặt cho nén hoặc giải nén.

public SevenZipCompressionSettings CompressionSettings { get; }

Giá trị thuộc tính

SevenZipCompressionSettings

FileAttributes

Lấy thuộc tính tệp từ hệ thống chủ.

protected FileAttributes FileAttributes { get; }

Giá trị thuộc tính

FileAttributes

IsDirectory

Lấy giá trị cho biết liệu mục có đại diện cho thư mục hay không.

public bool IsDirectory { get; }

Giá trị thuộc tính

bool

ModificationTime

Lấy ngày và giờ sửa đổi cuối cùng.

public DateTime ModificationTime { get; }

Giá trị thuộc tính

DateTime

Name

Lấy tên của mục trong kho lưu trữ.

public string Name { get; protected set; }

Giá trị thuộc tính

string

Source

Lấy luồng dữ liệu nguồn cho mục.

protected Stream Source { get; set; }

Giá trị thuộc tính

Stream

UncompressedSize

Lấy kích thước của tệp gốc.

public ulong UncompressedSize { get; }

Giá trị thuộc tính

ulong

Phương thức

Extract(string, string)

Giải nén mục vào hệ thống tệp theo đường dẫn đã cung cấp.

public FileInfo Extract(string path, string password = null)

Tham số

path string

Đường dẫn đến tệp đích. Nếu tệp đã tồn tại, nó sẽ bị ghi đè.

password string

Mật khẩu tùy chọn cho việc giải mã.

Trả về

FileInfo

Thông tin tệp của tệp đã tạo.

Ví dụ

using (var archive = new SevenZipArchive("archive.7z"))
{
    archive.Entries[0].Extract("data.bin");
}

Ngoại lệ

ArgumentNullException

path là null.

SecurityException

Người gọi không có quyền truy cập cần thiết.

ArgumentException

path là rỗng, chỉ chứa khoảng trắng hoặc chứa ký tự không hợp lệ.

UnauthorizedAccessException

Truy cập vào tệp path bị từ chối.

PathTooLongException

path, tên tệp hoặc cả hai vượt quá chiều dài tối đa do hệ thống xác định. Ví dụ, trên các nền tảng Windows, đường dẫn phải nhỏ hơn 248 ký tự, và tên tệp phải nhỏ hơn 260 ký tự.

NotSupportedException

Tệp tại path chứa dấu hai chấm (:) ở giữa chuỗi.

InvalidDataException

Kho lưu trữ bị hỏng.

Extract(Stream, string)

Giải nén mục vào luồng đã cung cấp.

public void Extract(Stream destination, string password = null)

Tham số

destination Stream

Luồng đích. Phải có khả năng ghi.

password string

Mật khẩu tùy chọn cho việc giải mã.

Ví dụ

Giải nén một mục của kho lưu trữ zip với mật khẩu.

using (var archive = new SevenZipArchive("archive.7z"))
{
    archive.Entries[0].Extract(httpResponseStream);
}

Ngoại lệ

ArgumentException

destination không hỗ trợ ghi.

InvalidOperationException

Kho lưu trữ không được mở để giải nén. - hoặc - Mục này là một thư mục.

InvalidDataException

Dữ liệu sai trong mục.

FinalizeCompressedData(Stream, byte[])

Ghi vào luồng đầu ra bất kỳ tiêu đề nào theo sau dữ liệu đã nén.

protected abstract int FinalizeCompressedData(Stream outputStream, byte[] encoderProperties)

Tham số

outputStream Stream

Luồng đầu ra cho mục.

encoderProperties byte[]

Thuộc tính của bộ nén.

Trả về

int

Số “byte kỹ thuật” đã được thêm vào sau khối dữ liệu quan trọng của mục.

GetDestinationStream(Stream)

Luồng đích cho mục, có thể được trang trí.

protected abstract Stream GetDestinationStream(Stream outputStream)

Tham số

outputStream Stream

Luồng đầu ra cho mục.

Trả về

Stream

Luồng đích cho nén mục.

Open(string)

Mở mục để giải nén và cung cấp một luồng với nội dung của mục.

public Stream Open(string password = null)

Tham số

password string

Mật khẩu tùy chọn cho việc giải mã.

Trả về

Stream

Luồng đại diện cho nội dung của mục.

Ví dụ

Sử dụng: Stream decompressed = entry.Open();

.NET 4.0 và cao hơn - sử dụng phương thức Stream.CopyTo: decompressed.CopyTo(httpResponse.OutputStream)

.NET 3.5 và trước đó - sao chép byte bằng tay:

byte[] buffer = new byte[8192];
int bytesRead;
while (0 < (bytesRead = decompressed.Read(buffer, 0, buffer.Length)))
 fileStream.Write(buffer, 0, bytesRead);
```</p>

#### Nhận xét

Đọc từ luồng để lấy nội dung gốc của tệp. Xem phần  dụ.

#### Ngoại lệ

 [InvalidOperationException](https://learn.microsoft.com/dotnet/api/system.invalidoperationexception)

Kho lưu trữ không được mở để giải nén. - hoặc - Mục này  một thư mục.

 [InvalidDataException](https://learn.microsoft.com/dotnet/api/system.io.invaliddataexception)

Dữ liệu sai trong mục.

### <a id="Aspose_Zip_SevenZip_SevenZipArchiveEntry_CompressionProgressed"></a> CompressionProgressed

Tăng lên khi một phần của luồng thô được nén.

```csharp
public event EventHandler<progresseventargs> CompressionProgressed

Loại sự kiện

EventHandler<ProgressEventArgs&gt;

Ví dụ

archive.Entries[0].CompressionProgressed += (s, e) =&gt; { int percent = (int)((100 * (long)e.ProceededBytes) / entrySourceStream.Length); };

Nhận xét

Người gửi sự kiện là một thể hiện của Aspose.Zip.SevenZip.SevenZipArchiveEntry.

Không được gọi trong chế độ đa luồng cho các mục LZMA2.

 Tiếng Việt