/** * Serialize a single file. * * @param FileEntry $file The file to serialize. * * @return StreamWriter */ private function serializeFile(FileEntry $file) { $result = new StreamWriter('php://temp'); $fileName = $file->getFilename(); $metaData = $file->getMetadata(); if (!empty($metaData)) { $metaData = serialize($metaData); } $result->writeUint32le(strlen($fileName))->write($fileName)->writeUint32le($file->getSizeUncompressed())->writeUint32le($file->getTime()->getTimestamp())->writeUint32le($file->getSizeCompressed())->writeUint32le($file->getCrc())->writeUint32le($file->getFlags())->writeUint32le(strlen($metaData))->write($metaData)->seek(0); $this->bins->write($file->getCompressedContent()); return $result; }
public function testWriteAutoCloseOn() { $value = get_test_string(); $value_size = strlen($value); $value_stream = string_to_stream($value); $stream = string_to_stream(""); $buffer_size = 1000; $writer = new StreamWriter($value_stream, $stream, $buffer_size); $this->assertSame("stream", get_resource_type($stream)); while ($ret = $writer->write(true)) { } // This works everywhere except Travis-CI, no idea why // $this->assertSame("Unknown", get_resource_type($stream)); }