Shellbox
Library and server for containerized shell execution
|
A streaming parser for multipart content. More...
Public Member Functions | |
__construct (StreamInterface $stream, string $boundary, $hmacKey=false) | |
readPreamble () | |
This must be called first on a new multipart stream, to discard any text before the first boundary. | |
readEpilogue () | |
Call this after the last part to read the epilogue, which runs from the closing boundary to the end of the stream. | |
readPartHeaders () | |
Read the part headers. | |
readPartAsString () | |
Read a part to a string buffer. | |
copyPartToStream (StreamInterface $outputStream) | |
Copy a part to the specified stream, which is open for writing. | |
readPartAsJson ( $headers) | |
Read a part to a string and decode the JSON found within. | |
getHash () | |
Get the HMAC of all the content in the stream. | |
Public Attributes | |
const | CHUNK_SIZE = 8192 |
A streaming parser for multipart content.
Typical usage: $reader = new MultipartReader( $stream, $boundary ); $reader->readPrologue(); while ( $headers = $reader->readPartHeaders() ) { $contents = $reader->readPartAsString(); } $reader->readEpilogue();
Shellbox\Multipart\MultipartReader::__construct | ( | StreamInterface | $stream, |
string | $boundary, | ||
$hmacKey = false ) |
StreamInterface | $stream | |
string | $boundary | |
string | false | $hmacKey |
Shellbox\Multipart\MultipartReader::copyPartToStream | ( | StreamInterface | $outputStream | ) |
Copy a part to the specified stream, which is open for writing.
StreamInterface | $outputStream |
Shellbox\Multipart\MultipartReader::getHash | ( | ) |
Get the HMAC of all the content in the stream.
This must be called after the reader has reached the end of the input stream.
MultipartError |
Shellbox\Multipart\MultipartReader::readPartAsJson | ( | $headers | ) |
Read a part to a string and decode the JSON found within.
array | $headers |
MultipartError |
Shellbox\Multipart\MultipartReader::readPartAsString | ( | ) |
Read a part to a string buffer.
Shellbox\Multipart\MultipartReader::readPartHeaders | ( | ) |
Read the part headers.
The Content-Disposition header is decoded, and its value is an associative array representing the header's parameters. Other headers are returned as strings.
The header names are converted to lower case.
Following the HTTP convention, we don't support line continuation. The writer we use (MultipartStream) doesn't use line continuation, so this lack of compliance should be harmless.
After reading the headers, the caller should call one of readPartAsString(), copyPartToStream() or readPartAsJson().
MultipartError |
Shellbox\Multipart\MultipartReader::readPreamble | ( | ) |
This must be called first on a new multipart stream, to discard any text before the first boundary.