GZFile
GZFile
- Full name:
\Hazaar\File\GZFile
- Parent class:
\Hazaar\File
Properties
level
private int $level
encoding
private int $encoding
handle
private null|resource $handle
Methods
__construct
public __construct(mixed $file = null, ?\Hazaar\File\Manager $manager = null): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$file | mixed | |
$manager | ?\Hazaar\File\Manager |
setCompressionLevel
Sets the level of compression.
public setCompressionLevel(int $level): void
Can be given as 0 for no compression up to 9 for maximum compression.
If -1 is used, the default compression of the zlib library is used which is 6.
Parameters:
Parameter | Type | Description |
---|---|---|
$level | int |
getCompressionLevel
Returns the current compression level setting.
public getCompressionLevel(): int
Can be a value of 0 for no compression up to 9 for maximum compression.
If the value is -1, the default compression of the zlib library is being used, which is 6.
setEncoding
Set the current encoding for compress.
public setEncoding(int $encoding): bool
Parameters:
Parameter | Type | Description |
---|---|---|
$encoding | int |
getEncoding
Returns the current gzencode encoding.
public getEncoding(): int
open
Open gz-file.
public open(string $mode = 'r'): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$mode | string |
close
Close an open gz-file pointer.
public close(): bool
read
Binary-safe gz-file read.
public read(int $length): false|string
File::read() reads up to length bytes from the file pointer referenced by handle. Reading stops as soon as one of the following conditions is met:
- length bytes have been read
- EOF (end of file) is reached
- a packet becomes available or the socket timeout occurs (for network streams)
- if the stream is read buffered and it does not represent a plain file, at most one read of up to a number of bytes equal to the chunk size (usually 8192) is made; depending on the previously buffered data, the size of the returned data may be larger than the chunk size.
Parameters:
Parameter | Type | Description |
---|---|---|
$length | int | up to length number of bytes read |
write
Binary-safe gz-file write.
public write(string $string, int $length = null): false|int
File::write() writes the contents of string to the file stream pointed to by handle.
Parameters:
Parameter | Type | Description |
---|---|---|
$string | string | the string that is to be written |
$length | int | If the length argument is given, writing will stop after length bytes have been written or the end of string is reached, whichever comes first. Note that if the length argument is given, then the magic_quotes_runtime configuration option will be ignored and no slashes will be stripped from string. |
getc
Returns a character from the file pointer.
public getc(): false|string
gets
Returns a line from the file pointer.
public gets(?int $length = null): false|string
Parameters:
Parameter | Type | Description |
---|---|---|
$length | ?int |
getss
Returns a line from the file pointer and strips HTML tags.
public getss(string[]|string $allowable_tags = null): false|string
Parameters:
Parameter | Type | Description |
---|---|---|
$allowable_tags | string[]|string |
seek
Seeks to a position in the file.
public seek(int $offset, int $whence = SEEK_SET): int
Parameters:
Parameter | Type | Description |
---|---|---|
$offset | int | The offset. To move to a position before the end-of-file, you need to pass a negative value in offset and set whence to SEEK_END. |
$whence | int | whence values are: SEEK_SET - Set position equal to offset bytes. SEEK_CUR - Set position to current location plus offset. SEEK_END - Set position to end-of-file plus offset. |
tell
Returns the current position of the file read/write pointer.
public tell(): false|int
rewind
Rewind the position of a file pointer.
public rewind(): bool
Sets the file position indicator for handle to the beginning of the file stream.
eof
Tests for end-of-file on a file pointer.
public eof(): bool
Return Value:
TRUE if the file pointer is at EOF or an error occurs; otherwise returns FALSE
get_contents
Returns the current contents of the file.
public get_contents(mixed $offset = -1, mixed $maxlen = null): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$offset | mixed | |
$maxlen | mixed |
putContents
Put contents directly writes data to the storage manager without storing it in the file object itself.
public putContents(string $data, bool $overwrite = true): ?int
NOTE: This function is called internally to save data that has been updated in the file object.
Parameters:
Parameter | Type | Description |
---|---|---|
$data | string | The data to write |
$overwrite | bool | Overwrite data if it exists |
saveAs
Saves this file objects content to another file name.
public saveAs(string $filename, bool $overwrite = false): ?int
Parameters:
Parameter | Type | Description |
---|---|---|
$filename | string | The filename to save as |
$overwrite | bool | Boolean flag to indicate that the destination should be overwritten if it exists |
Inherited methods
__construct
public __construct(mixed $file = null, ?\Hazaar\File\Manager $manager = null, ?string $relative_path = null): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$file | mixed | |
$manager | ?\Hazaar\File\Manager | |
$relative_path | ?string |
__toString
public __toString(): string
backend
public backend(): string
getManager
public getManager(): \Hazaar\File\Manager
get
public static get(string $url, ?\Hazaar\HTTP\Client $client = null): bool|\Hazaar\File
- This method is static.
Parameters:
Parameter | Type | Description |
---|---|---|
$url | string | |
$client | ?\Hazaar\HTTP\Client |
registerFilter
Content filters.
public registerFilter(int $type, \Closure|string $callable): bool
Parameters:
Parameter | Type | Description |
---|---|---|
$type | int | |
$callable | \Closure|string |
setMeta
public setMeta(array<string,mixed> $values): bool
Parameters:
Parameter | Type | Description |
---|---|---|
$values | array<string,mixed> |
getMeta
public getMeta(?string $key = null): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$key | ?string |
toString
public toString(): string
basename
public basename(string $suffix = ''): string
Parameters:
Parameter | Type | Description |
---|---|---|
$suffix | string |
dirname
public dirname(): string
name
public name(): string
fullpath
public fullpath(): string
relativepath
Get the relative path of the file.
public relativepath(mixed $path = null): bool|string
If the file was returned from a [[Hazaar\File\Dir]] object, then it will have a stored relative path. Otherwise any file/path can be provided in the form of another [[Hazaar\File\ object, [[Hazaar\File\Dir]] object, or string path, and the relative path to the file will be returned.
Parameters:
Parameter | Type | Description |
---|---|---|
$path | mixed | optional path to use as the relative path |
Return Value:
The relative path. False when $path is not valid
setRelativePath
public setRelativePath(string $path): void
Parameters:
Parameter | Type | Description |
---|---|---|
$path | string |
extension
public extension(): string
size
public size(): ?int
exists
public exists(): bool
realpath
public realpath(): string
isReadable
public isReadable(): bool
isWritable
public isWritable(): bool
isFile
public isFile(): bool
isDir
public isDir(): bool
isLink
public isLink(): bool
dir
public dir(): ?\Hazaar\File\Dir
parent
public parent(): \Hazaar\File\Dir
type
public type(): ?string
ctime
public ctime(): ?int
mtime
public mtime(): ?int
touch
public touch(): bool
atime
public atime(): ?int
hasContents
public hasContents(): bool
getContents
Returns the current contents of the file.
public getContents(int $offset = -1, ?int $maxlen = null): string
Parameters:
Parameter | Type | Description |
---|---|---|
$offset | int | |
$maxlen | ?int |
putContents
Put contents directly writes data to the storage backend without storing it in the file object itself.
public putContents(string $data, bool $overwrite = true): ?int
NOTE: This function is called internally to save data that has been updated in the file object.
Parameters:
Parameter | Type | Description |
---|---|---|
$data | string | The data to write |
$overwrite | bool | Overwrite data if it exists |
setContents
Sets the current contents of the file in memory.
public setContents(string $bytes): ?int
Calling this function does not directly update the content of the file "on disk". To do that you must call the File::save() method which will commit the data to storage.
Parameters:
Parameter | Type | Description |
---|---|---|
$bytes | string | The data to set as the content |
setDecodedContents
Set the contents from an encoded string.
public setDecodedContents(string $bytes): bool
Currently this supports only data URI encoded strings. I have made this generic in case I come across other types of encodings that will work with this method.
Parameters:
Parameter | Type | Description |
---|---|---|
$bytes | string |
getEncodedContents
Return the contents of the file as a data URI encoded string.
public getEncodedContents(): string
This function is basically the opposite of Hazaar\File::set_decoded_contents() and will generate a data URI based on the current MIME content type and the contents of the file.
save
Saves the current in-memory content to the storage backend.
public save(): ?int
Internally this calls File::putContents() to write the data to the backend.
saveAs
Saves this file objects content to another file name.
public saveAs(string $filename, bool $overwrite = false): ?int
Parameters:
Parameter | Type | Description |
---|---|---|
$filename | string | The filename to save as |
$overwrite | bool | Boolean flag to indicate that the destination should be overwritten if it exists |
unlink
Deletes the file from storage.
public unlink(): bool
md5
Generate an MD5 checksum of the current file content.
public md5(): string
base64
Return the base64 encoded content.
public base64(): string
parseJSON
Returns the contents as decoded JSON.
public parseJSON(bool $assoc = false): array|\stdClass
If the content is a JSON encoded string, this will decode the string and return it as a stdClass object, or an associative array if the $assoc parameter is TRUE.
If the content can not be decoded because it is not a valid JSON string, this method will return FALSE.
Parameters:
Parameter | Type | Description |
---|---|---|
$assoc | bool | Return as an associative array. Default is to use stdClass. |
moveTo
public moveTo(string $destination, bool $overwrite = false, bool $create_dest = false, ?\Hazaar\File\Manager $dstManager = null): bool|\Hazaar\File
Parameters:
Parameter | Type | Description |
---|---|---|
$destination | string | |
$overwrite | bool | |
$create_dest | bool | |
$dstManager | ?\Hazaar\File\Manager |
copyTo
Copy the file to another folder.
public copyTo(string $destination, bool $overwrite = false, bool $create_dest = false, \Hazaar\File\Manager $dstManager = null): bool|\Hazaar\File
This differs to copy() which expects the target to be the full new file pathname.
Parameters:
Parameter | Type | Description |
---|---|---|
$destination | string | The destination folder to copy the file into |
$overwrite | bool | overwrite the destination file if it exists |
$create_dest | bool | Flag that indicates if the destination folder should be created. If the destination does not exist an error will be thrown. |
$dstManager | \Hazaar\File\Manager | The destination file manager. Defaults to the same manager as the source. |
Throws:
copy
Copy the file to another folder and filename.
public copy(string $destination, bool $overwrite = false, bool $create_dest = false, mixed $dstManager = null): bool|\Hazaar\File
This differs from copyTo which expects the target to be a folder
Parameters:
Parameter | Type | Description |
---|---|---|
$destination | string | The destination folder and file name to copy the file into |
$overwrite | bool | overwrite the destination file if it exists |
$create_dest | bool | Flag that indicates if the destination folder should be created. If the destination does not exist an error will be thrown. |
$dstManager | mixed | The destination file manager. Defaults to the same manager as the source. |
Throws:
mimeContentType
public mimeContentType(): ?string
setMimeContentType
public setMimeContentType(string $type): void
Parameters:
Parameter | Type | Description |
---|---|---|
$type | string |
thumbnailURL
public thumbnailURL(int $width = 100, int $height = 100, string $format = 'jpeg', array<string,int|string> $params = []): ?string
Parameters:
Parameter | Type | Description |
---|---|---|
$width | int | |
$height | int | |
$format | string | |
$params | array<string,int|string> |
previewURL
public previewURL(array<string,string> $params = []): ?string
Parameters:
Parameter | Type | Description |
---|---|---|
$params | array<string,string> |
directURL
public directURL(): ?string
mediaURL
public mediaURL(null|string|\Hazaar\HTTP\URL $set_path = null): \Hazaar\HTTP\URL
Parameters:
Parameter | Type | Description |
---|---|---|
$set_path | null|string|\Hazaar\HTTP\URL |
toArray
public toArray(string $delimiter = "
"): string[]
Parameters:
Parameter | Type | Description |
---|---|---|
$delimiter | string |
readCSV
Return the CSV content as a parsed array.
public readCSV(bool $use_header_row = false): string[][]
Parameters:
Parameter | Type | Description |
---|---|---|
$use_header_row | bool | Indicates if a header row should be parsed and used to build an associative array. In this case the keys in the returned array will be the values from the first row, which is normally a header row. |
getcsv
Returns a line from the file pointer and parse for CSV fields.
public getcsv(int $length, string $delimiter = ',', string $enclosure = '"', string $escape = '\'): string[]
Parameters:
Parameter | Type | Description |
---|---|---|
$length | int | Must be greater than the longest line (in characters) to be found in the CSV file (allowing for trailing line-end characters). Otherwise the line is split in chunks of length characters, unless the split would occur inside an enclosure. Omitting this parameter (or setting it to 0 in PHP 5.1.0 and later) the maximum line length is not limited, which is slightly slower. |
$delimiter | string | the optional delimiter parameter sets the field delimiter (one character only) |
$enclosure | string | the optional enclosure parameter sets the field enclosure character (one character only) |
$escape | string | the optional escape parameter sets the escape character (one character only) |
putcsv
Writes an array to the file in CSV format.
public putcsv((int|string)[] $fields, string $delimiter = ',', string $enclosure = '"', string $escape = '\'): null|int
Parameters:
Parameter | Type | Description |
---|---|---|
$fields | (int|string)[] | Must be greater than the longest line (in characters) to be found in the CSV file (allowing for trailing line-end characters). Otherwise the line is split in chunks of length characters, unless the split would occur inside an enclosure. Omitting this parameter (or setting it to 0 in PHP 5.1.0 and later) the maximum line length is not limited, which is slightly slower. |
$delimiter | string | the optional delimiter parameter sets the field delimiter (one character only) |
$enclosure | string | the optional enclosure parameter sets the field enclosure character (one character only) |
$escape | string | the optional escape parameter sets the escape character (one character only) |
rename
Renames a file or directory.
public rename(string $newname): bool
NOTE: This will not work if the file is currently opened by another process.
Parameters:
Parameter | Type | Description |
---|---|---|
$newname | string | The new name. Must not be an absolute/relative path. If you want to move the file use File::moveTo(). |
delete
public static delete(string $path): bool
- This method is static.
Parameters:
Parameter | Type | Description |
---|---|---|
$path | string |
jsonSerialize
public jsonSerialize(): mixed
perms
public perms(): ?int
chmod
public chmod(int $mode): bool
Parameters:
Parameter | Type | Description |
---|---|---|
$mode | int |
isEncrypted
Check if a file is encrypted using the built-in Hazaar encryption method.
public isEncrypted(): bool
encrypt
public encrypt(): bool
decrypt
public decrypt(): bool
isOpen
public isOpen(): bool
open
public open(string $mode): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$mode | string |
read
public read(int $length): false|string
Parameters:
Parameter | Type | Description |
---|---|---|
$length | int |
write
public write(string $bytes, int $length): false|int
Parameters:
Parameter | Type | Description |
---|---|---|
$bytes | string | |
$length | int |
seek
public seek(int $offset, int $whence = SEEK_SET): int
Parameters:
Parameter | Type | Description |
---|---|---|
$offset | int | |
$whence | int |
tell
public tell(): false|int
eof
public eof(): bool
truncate
public truncate(int $size): bool
Parameters:
Parameter | Type | Description |
---|---|---|
$size | int |
lock
public lock(int $operation, ?int& $wouldblock = null): bool
Parameters:
Parameter | Type | Description |
---|---|---|
$operation | int | |
$wouldblock | ?int |
flush
public flush(): bool
gets
public gets(?int $length = null): false|string
Parameters:
Parameter | Type | Description |
---|---|---|
$length | ?int |
close
public close(): bool
filterIn
Internal content filter.
protected filterIn(string& $content): bool
Checks if the content is modified in some way using a BOM mask. Currently this is used to determine if a file is encrypted and automatically decrypts it if an encryption key is available.
Parameters:
Parameter | Type | Description |
---|---|---|
$content | string |
filterOut
Internal content filter.
protected filterOut(string& $content): bool
Checks if the content is modified in some way using a BOM mask. Currently this is used to determine if a file is encrypted and automatically decrypts it if an encryption key is available.
Parameters:
Parameter | Type | Description |
---|---|---|
$content | string |
getEncryptionKey
private getEncryptionKey(): string
Automatically generated on 2024-11-14