Class ArchiveEntry

Class ArchiveEntry

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

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

public abstract class ArchiveEntry : IArchiveFileEntry

Kế thừa

objectArchiveEntry

Kế thừa

ArchiveEntryEncrypted, ArchiveEntryPlain

Thực hiện

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 instance của Aspose.Zip.ArchiveEntry sang Aspose.Zip.ArchiveEntryEncrypted để xác định xem mục có được mã hóa hay không.

Bộ xây dựng

ArchiveEntry(string, CompressionSettings, Func<stream>, FileAttributes)

Khởi tạo một instance mới của lớp Aspose.Zip.ArchiveEntry.

protected ArchiveEntry(string name, CompressionSettings compressionSettings, Func<stream> sourceProvider, FileAttributes fileAttributes)

Tham số

name string

Tên mục.

compressionSettings CompressionSettings

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

sourceProvider Func<Stream&gt;

Phương thức trả về luồng với dữ liệu mục cần nén.

fileAttributes FileAttributes

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

ArchiveEntry(string, CompressionSettings, Stream, FileAttributes, FileSystemInfo)

Khởi tạo một instance mới của lớp Aspose.Zip.ArchiveEntry.

protected ArchiveEntry(string name, CompressionSettings compressionSettings, Stream source, FileAttributes fileAttributes, FileSystemInfo fileInfo = null)

Tham số

name string

Tên mục.

compressionSettings CompressionSettings

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

source Stream

Luồng với 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.

Thuộc tính

Comment

Lấy nhận xét của mục trong kho lưu trữ.

public string Comment { get; protected set; }

Giá trị thuộc tính

string

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 CompressionSettings CompressionSettings { get; }

Giá trị thuộc tính

CompressionSettings

DataSource

Nguồn cho mục nếu mục đã được thêm vào kho lưu trữ, không phải là được giải nén.

public Stream DataSource { get; }

Giá trị thuộc tính

Stream

Nhận xét

Trước khi gán, nguồn là null. Nguồn này có thể được gán trong phương thức Archive.Save trong một số trường hợp.

FileAttributes

Lấy thuộc tính tệp từ hệ thống máy 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 hoặc thiết lập ngày và giờ sửa đổi cuối cùng.

public DateTime ModificationTime { get; set; }

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

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 giải mã.

Trả về

FileInfo

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

Ví dụ

Giải nén hai mục của kho lưu trữ zip, mỗi mục có mật khẩu riêng

using (FileStream zipFile = File.Open("archive.zip", FileMode.Open))
{
    using (Archive archive = new Archive(zipFile))
    {
        archive.Entries[0].Extract("first.bin", "first_pass");
        archive.Entries[1].Extract("second.bin", "second_pass");
    }
}

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á độ dài tối đa do hệ thống xác định. Ví dụ, trên các nền tảng Windows, các đường dẫn phải ngắn hơn 248 ký tự và tên tệp phải ngắn hơn 260 ký tự.

NotSupportedException

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

FileNotFoundException

Tệp không được tìm thấy.

DirectoryNotFoundException

Đường dẫn đã chỉ định không hợp lệ, chẳng hạn như nằm trên một ổ đĩa không được ánh xạ.

IOException

Tệp đã được mở.

InvalidDataException

Dữ liệu bị hỏng. -hoặc- Xác minh CRC hoặc MAC không thành công cho mục.

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ó thể ghi.

password string

Mật khẩu tùy chọn cho 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 (FileStream zipFile = File.Open("archive.zip", FileMode.Open))
{
    using (Archive archive = new Archive(zipFile))
    {
        archive.Entries[0].Extract(httpResponseStream, "p@s$");
    }
}

Ngoại lệ

InvalidDataException

Dữ liệu bị hỏng. -hoặc- Xác minh CRC hoặc MAC không thành công cho mục.

IOException

Nguồn bị hỏng hoặc không thể đọc.

ArgumentException

destination không hỗ trợ ghi.

Open(string)

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

public Stream Open(string password = null)

Tham số

password string

Mật khẩu tùy chọn cho 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 thủ công:

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

#### Nhận xét

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

#### Ngoại lệ

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

Kho lưu trữ đang  trạng thái không chính xác.

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

Được nâ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 instance của Aspose.Zip.ArchiveEntry.

ExtractionProgressed

Được nâng lên khi một phần của luồng thô được giải nén.

public event EventHandler<progresseventargs> ExtractionProgressed

Loại sự kiện

EventHandler<ProgressEventArgs&gt;

Ví dụ

archive.Entries[0].ExtractionProgressed += (s, e) =&gt; { int percent = (int)((100 * e.ProceededBytes) / ((ArchiveEntry)s).UncompressedSize); };

Nhận xét

Người gửi sự kiện là một instance của Aspose.Zip.ArchiveEntry.

 Tiếng Việt