ELP Parser API

ArchiveReader
in package

Read and safely extract ZIP-based eXeLearning project files.

Tags
category

Parser

author

INTEF cedec@educacion.gob.es

license

MIT https://opensource.org/licenses/MIT

link
https://github.com/exelearning/elp-parser

Table of Contents

Constants

ZIP_OPSYS_UNIX  : mixed = 3

Properties

$filePath  : string
$limits  : ArchiveLimits

Methods

__construct()  : mixed
copyEntryToStream()  : int
Copy one archive entry to a writable PHP stream.
extract()  : void
Extract all entries while preserving configured resource limits.
extractEntry()  : void
Extract one archive entry to an explicit filesystem path.
hasEntry()  : bool
Determine whether an archive entry exists.
hashArchive()  : string
Hash the complete archive file.
hashEntry()  : string
Hash one ZIP entry without loading it entirely into memory.
inspect()  : array<int, string>
Validate the archive and return its entry names.
readEntry()  : string
Read one archive entry with a hard byte limit.
assertHashAlgorithm()  : void
Validate a requested hash algorithm.
assertNotSymlink()  : void
Reject Unix symlink entries stored in ZIP metadata.
assertSafeEntryName()  : void
Validate an archive path before any filesystem operation.
createSafeDirectory()  : void
Create or validate a directory inside the extraction root.
isPathWithinRoot()  : bool
Check whether a canonical path is located inside the destination root.
openArchive()  : ZipArchive
Open the configured ZIP archive.
readStreamWithLimit()  : string
Read a stream without allowing it to exceed a byte limit.
writeAll()  : void
Write the complete buffer to a stream.

Constants

Properties

Methods

copyEntryToStream()

Copy one archive entry to a writable PHP stream.

public copyEntryToStream(string $entryName, resource $output[, int|null $maxBytes = null ]) : int
Parameters
$entryName : string

Entry name.

$output : resource

Writable stream.

$maxBytes : int|null = null

Optional byte limit.

Return values
int

Number of bytes written.

extract()

Extract all entries while preserving configured resource limits.

public extract(string $destinationPath) : void
Parameters
$destinationPath : string

Destination directory.

extractEntry()

Extract one archive entry to an explicit filesystem path.

public extractEntry(string $entryName, string $destinationPath[, int|null $maxBytes = null ]) : void
Parameters
$entryName : string

Entry name.

$destinationPath : string

Destination file path.

$maxBytes : int|null = null

Optional byte limit.

hasEntry()

Determine whether an archive entry exists.

public hasEntry(string $entryName) : bool
Parameters
$entryName : string

Entry name.

Return values
bool

hashArchive()

Hash the complete archive file.

public hashArchive([string $algorithm = 'sha256' ]) : string
Parameters
$algorithm : string = 'sha256'

Hash algorithm.

Return values
string

hashEntry()

Hash one ZIP entry without loading it entirely into memory.

public hashEntry(string $entryName[, string $algorithm = 'sha256' ]) : string
Parameters
$entryName : string

Entry name.

$algorithm : string = 'sha256'

Hash algorithm.

Return values
string

inspect()

Validate the archive and return its entry names.

public inspect() : array<int, string>
Return values
array<int, string>

readEntry()

Read one archive entry with a hard byte limit.

public readEntry(string $entryName[, int|null $maxBytes = null ]) : string
Parameters
$entryName : string

Entry name.

$maxBytes : int|null = null

Optional byte limit.

Return values
string

assertHashAlgorithm()

Validate a requested hash algorithm.

private assertHashAlgorithm(string $algorithm) : void
Parameters
$algorithm : string

Hash algorithm.

Reject Unix symlink entries stored in ZIP metadata.

private assertNotSymlink(ZipArchive $zip, int $index, string $entryName) : void
Parameters
$zip : ZipArchive

ZIP archive.

$index : int

Entry index.

$entryName : string

Entry name.

assertSafeEntryName()

Validate an archive path before any filesystem operation.

private assertSafeEntryName(string $entryName) : void
Parameters
$entryName : string

ZIP entry name.

createSafeDirectory()

Create or validate a directory inside the extraction root.

private createSafeDirectory(string $directory, string $destinationRoot) : void
Parameters
$directory : string

Directory to create or validate.

$destinationRoot : string

Canonical extraction root.

isPathWithinRoot()

Check whether a canonical path is located inside the destination root.

private isPathWithinRoot(string $path, string $root) : bool
Parameters
$path : string

Path to check.

$root : string

Extraction root.

Return values
bool

openArchive()

Open the configured ZIP archive.

private openArchive() : ZipArchive
Return values
ZipArchive

readStreamWithLimit()

Read a stream without allowing it to exceed a byte limit.

private readStreamWithLimit(resource $stream, int $limit, string $entryName) : string
Parameters
$stream : resource

Input stream.

$limit : int

Maximum bytes.

$entryName : string

Entry name for diagnostics.

Return values
string

writeAll()

Write the complete buffer to a stream.

private writeAll(resource $stream, string $contents, string $entryName) : void
Parameters
$stream : resource

Output stream

$contents : string

Buffer to write

$entryName : string

Archive entry name for error reporting

On this page

Search results