ZipArchiveEntry Class - raravel/libzip GitHub Wiki

This class like C# ZipArchiveEntry

Represents a compressed file within a zip archive.

Properties

CentralDirectory ( get/set )

Type: CentralDirectory CentralDirectory of this entry.

LocalFileHeader ( get/set )

Type: LocalFileHeader LocalFileHeader of this entry.

Archive ( get )

Type: ZipArchive Gets the zip archive that the entry belongs to.

CompressedLength ( get )

Type: Number Gets the compressed size of the entry in the zip archive.

Crc32 ( get )

Type: Number The 32-bit Cyclic Redundant Check.

ExternalAttributes ( get/set )

Type: Number OS and application specific file attributes.

FullName ( get )

Type: String Gets the relative path of the entry in the zip archive.

LastWriteTime ( get/set )

Type: Date Gets or sets the last time the entry in the zip archive was changed.

Length ( get )

Type: Number Gets the uncompressed size of the entry in the zip archive.

Name ( get )

Type: String Gets the file name of the entry in the zip archive.

Methods

Init

Read & Initial LocalFileHeader structure of this entry.

Source: libzip.ts:141

Arguments

Type Name Description Necessary

Example

Delete

Deletes the entry from the zip archive.

Source: libzip.ts:146

Arguments

Type Name Description Necessary

Example

import { ZipFile, ZipArchive, ZIpArchiveEntry } from 'libzip';

const archive: ZipArchive = ZipFile.Open('zip file.zip');
const entry: ZipArchiveEntry = archive.GetEntry('entry name');
entry.Delete();
archive.Save();

Read

Read the entry from the zip archive.

Source: libzip.ts:155

Arguments

Type Name Description Necessary

Example

import { ZipFile, ZipArchive, ZIpArchiveEntry } from 'libzip';
import fs from 'fs';

const archive: ZipArchive = ZipFile.Open('zip file.zip');
const entry: ZipArchiveEntry = archive.GetEntry('entry name');
const buf: Buffer = entry.Read();
fs.writeFileSync('file name', buf);

Write

Read the entry from the zip archive.

Source: libzip.ts:162

Arguments

Type Name Description Necessary

Example

import { ZipFile, ZipArchive, ZIpArchiveEntry } from 'libzip';
import fs from 'fs';

const archive: ZipArchive = ZipFile.Open('zip file.zip');
const entry: ZipArchiveEntry = archive.CreateEntry('new entry name');
const buf: Buffer = fs.readFileSync('file');
entry.Write(buf);

ExtractEntry

Extract the file in the specified zip archive to a file on the file system.

Source: libzip.ts:182

Arguments

Type Name Description Necessary
String dir Extract target directory FALSE

Example

import { ZipFile, ZipArchive, ZipArchiveEntry } from 'libzip';

const archive: ZipArchive = ZipFile.Open('zip file.zip');
const entry: ZipArchiveEntry = archive.GetEntry('entry name');
entry.ExtractEntry(); // __dirname directory
/* do something */