\seekquarry\yioop\libraryWebArchive

Code used to manage web archive files

Summary

Methods
Properties
Constants
__construct()
readInfoBlock()
writeInfoBlock()
seekEndObjects()
addObjects()
open()
close()
getObjects()
currentObjects()
nextObjects()
reset()
$filename
$iterator_pos
$compressor
$count
$version
$is_string
$storage
WEB_ARCHIVE_VERSION
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Constants

WEB_ARCHIVE_VERSION

WEB_ARCHIVE_VERSION

Version number to use in the WebArchive header if constructing a new archive

Properties

$filename

$filename : string

Filename used to store the web archive.

Type

string

$iterator_pos

$iterator_pos : integer

Current offset into the web archive the iterator for the archive is at (at most one iterator / archive -- oh well)

Type

integer

$compressor

$compressor : object

Filter object used to compress/uncompress objects stored in archive

Type

object

$count

$count : integer

number of item in archive

Type

integer

$version

$version : float

version number of the current archive

Type

float

$is_string

$is_string : boolean

Says whether the archive is a string archive

Type

boolean

$storage

$storage : string

If archive is stored as a string rather than persistently to disk then $storage is used to hold the string

Type

string

Methods

__construct()

__construct(string  $fname, string  $compressor, boolean  $fast_construct = false, boolean  $is_string = false) 

Makes or initializes a WebArchive object using the supplied parameters

Parameters

string $fname

filename to use to store archive to disk

string $compressor

what kind of Compressor object should be used to read and write objects in the archive

boolean $fast_construct

do we read the info block of the web archive as part of the constructing process

boolean $is_string

says whether the archive stores to string rather than a file

readInfoBlock()

readInfoBlock() : array

Read the info block associated with this web archive.

The info block is meta data for the archive stored at the end of the WebArchive file. The particular meta is up to who is using the web archive.

Returns

array —

the contents of the info block

writeInfoBlock()

writeInfoBlock(resource  $fh = null, \seekquarry\yioop\library\array&  $data = null) 

Serializes and applies the compressor to an info block and write it at the end of the web archive The info block is meta data for the archive stored at the end of the WebArchive file. The particular meta is up to who is using the web archive; however, count and archive version number are always stored

Parameters

resource $fh

resource for the web archive file. If null the web archive is open first and close when the data is written

\seekquarry\yioop\library\array& $data

data to write into the info block of the archive

seekEndObjects()

seekEndObjects(resource  $fh) : integer

Seeks in the WebArchive file to the end of the last Object.

The last $compressed_int_len bytes of a WebArchive say the length of an info block in bytes

Parameters

resource $fh

resource for the WebArchive file

Returns

integer —

offset length of info block

addObjects()

addObjects(string  $offset_field, \seekquarry\yioop\library\array&  $objects, array  $data = null, string  $callback = null, boolean  $return_flag = true) : mixed

Adds objects to the WebArchive

Parameters

string $offset_field

field in objects to return the byte offset at which they were stored

\seekquarry\yioop\library\array& $objects

references to objects that will be stored the offset field in these references will be adjusted if

array $data

data to write in the WebArchive's info block

string $callback

name of a callback $callback($data, $new_objects, $offset_field) used to modify $data before it is written to the info block. For instance, we can add offset info to data.

boolean $return_flag

if true rather than adjust the offsets by reference, create copy objects and adjust their offsets and return

Returns

mixed —

adjusted objects or void

open()

open(string  $mode = "r") : resource

Open the web archive file associated with this WebArchive object.

Parameters

string $mode

read/write mode to open file with

Returns

resource —

a file resource for the web archive

close()

close(resource  $fh) 

Closes a file handle (which should be of a web archive)

Parameters

resource $fh

filehandle to close

getObjects()

getObjects(integer  $offset, integer  $num, boolean  $next_flag = true, resource  $fh = null, integer  $max_size = \seekquarry\yioop\configs\MAX_ARCHIVE_OBJECT_SIZE) : array

Gets $num many objects out of the web archive starting at byte $offset

If the $next_flag is true the archive iterator is advance and if $fh is not null then it is assumed to be an open resource pointing to the archive (saving the time to open it).

Parameters

integer $offset

a valid byte offset into a web archive

integer $num

number of objects to return

boolean $next_flag

whether to advance the archive iterator

resource $fh

either null or a file resource to the archive

integer $max_size

maximum size returned object should be, use as a sanity check against corrupted archives

Returns

array —

the $num objects beginning at $offset

currentObjects()

currentObjects(integer  $num) : array

Returns $num many objects from the web archive starting at the current iterator position, leaving the iterator position unchanged

Parameters

integer $num

number of objects to return

Returns

array —

an array of objects from the web archive

nextObjects()

nextObjects(integer  $num) : array

Returns $num many objects from the web archive starting at the current iterator position. The iterator is advance to the object after the last one returned

Parameters

integer $num

number of objects to return

Returns

array —

an array of objects from the web archive

reset()

reset() 

Resets the iterator for this web archive to the first object in the archive