class FileUtils

Helper class for reading/writing streams and files via chunks

Methods

static string
ReadStream(resource $stream, int $bytes, bool $strict = true)

Reads from the given stream (since fread may only return 8K)

static void
WriteStream(resource $stream, string $data)

Writes data to the given stream

static void
DoChunkedRead(File $file, int $fstart, int $flast, int $chunksize, bool $align, bool $debugdl = false)

Performs a chunked File read, echoing output and counting bandwidth

static int
DoChunkedWrite(resource $handle, File $file, int $wstart, int $chunksize, bool $align)

Perform a chunked write to a file

static int
GetChunkSize(int $chunksize, int|null $fschunksize = null)

Returns the chunk size to use for reading/writing a file

static void
ChunkedRead(ObjectDatabase $database, File $file, int $fstart, int $flast, bool $debugdl = false)

Peform a chunked file read to stdout

static int
ChunkedWrite(ObjectDatabase $database, resource $handle, File $file, int $wstart)

Perform a chunked write to a file

Details

at line 21
static string ReadStream(resource $stream, int $bytes, bool $strict = true)

Reads from the given stream (since fread may only return 8K)

Parameters

resource $stream

stream to read from

int $bytes

number of bytes to read

bool $strict

if true, want exactly $bytes, else up to

Return Value

string

read data

Exceptions

FileReadFailedException

if reading the stream fails

at line 54
static void WriteStream(resource $stream, string $data)

Writes data to the given stream

Parameters

resource $stream

stream to write

string $data

data to write

Return Value

void

Exceptions

FileWriteFailedException

if fails

at line 87
static void DoChunkedRead(File $file, int $fstart, int $flast, int $chunksize, bool $align, bool $debugdl = false)

Performs a chunked File read, echoing output and counting bandwidth

Parameters

File $file

file to read from

int $fstart

first byte to read

int $flast

last byte to read (inclusive!)

int $chunksize

read chunk size

bool $align

if true, align reads to chunk size multiples

bool $debugdl

if true, don't actually echo anything

Return Value

void

Exceptions

FileReadFailedException

if reading the file fails

at line 120
static int DoChunkedWrite(resource $handle, File $file, int $wstart, int $chunksize, bool $align)

Perform a chunked write to a file

Parameters

resource $handle

input data handle

File $file

write destination

int $wstart

write offset

int $chunksize

write chunksize

bool $align

if true, align to chunksize multiples

Return Value

int

number of bytes written

Exceptions

FileReadFailedException

if reading input fails

at line 147
static int GetChunkSize(int $chunksize, int|null $fschunksize = null)

Returns the chunk size to use for reading/writing a file

Based on the configured RW chunk size and the file's FS chunk size We want to use the RW size but MUST use a multiple of the FS size

Parameters

int $chunksize

the configured RW chunk size

int|null $fschunksize

filesystem chunksize (or null)

Return Value

int

chunk size in bytes

at line 164
static void ChunkedRead(ObjectDatabase $database, File $file, int $fstart, int $flast, bool $debugdl = false)

Peform a chunked file read to stdout

Parameters

ObjectDatabase $database

database reference

File $file

file to read

int $fstart

byte offset to start reading

int $flast

last byte to read (inclusive)

bool $debugdl

Return Value

void

See also

\Andromeda\Apps\Files\self::DoChunkedRead()

at line 182
static int ChunkedWrite(ObjectDatabase $database, resource $handle, File $file, int $wstart)

Perform a chunked write to a file

Parameters

ObjectDatabase $database

reference

resource $handle

input data handle

File $file

write destination

int $wstart

write offset

Return Value

int

number of bytes written

See also

\Andromeda\Apps\Files\self::DoChunkedWrite()