public function testRead() { $stream = new Yamdi_InputStream($this->testFileName); $this->assertEqual($stream->getPosition(), 0); $this->assertFalse($stream->isEnd()); $bytes = $stream->read(3); $this->assertEqual($bytes, '123'); $this->assertEqual($stream->getPosition(), 3); $this->assertEqual($bytes, '123'); $this->assertFalse($stream->isEnd()); $stream->seek(+2); $this->assertEqual($stream->getPosition(), 5); $this->assertFalse($stream->isEnd()); $bytes = $stream->read(1); $this->assertEqual($bytes, 'c'); $this->assertEqual($stream->getPosition(), 6); $this->assertFalse($stream->isEnd()); /* trying to read beyont the eof */ $bytes = $stream->read(2); $this->assertTrue($stream->isEnd()); // end of file is reached $this->assertEqual($stream->getPosition(), 6); // position is not changed $this->assertEqual($bytes, ''); // void is read $stream->close(); }
/** * Translates data from $source to an output file without changes * * @param Yamdi_InputStream $source * @param int $fromPosition */ public function passthrough(Yamdi_InputStream $source, $fromPosition, $size = null) { $source->seek($fromPosition); if (null === $size) { while ($data = $source->read($this->passthrough_chunk_size)) { $this->write($data); } } else { $this->write($source->read($size)); } }
public function read(Yamdi_InputStream $stream) { if ($stream->isEnd()) { return false; } $content = $stream->read($this->calculateSize()); if ($content === false || $content == '') { return false; } else { return $this->unpack($content); } }
public function readTagBodyBytes(Yamdi_InputStream $stream, $count) { $this->bodyBytesRead += $count; return $stream->read($count); }