Skip to content

Commit

Permalink
IMP_Compose_Attachment_Storage#read() now returns a Horde_Stream object
Browse files Browse the repository at this point in the history
  • Loading branch information
slusarz committed Nov 7, 2013
1 parent 6f1ffae commit 6a21150
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 19 deletions.
2 changes: 1 addition & 1 deletion imp/lib/Compose/Attachment.php
Expand Up @@ -156,7 +156,7 @@ public function getPart($build = false)
$data = is_null($this->tmpfile)
? $this->storage->read()
: fopen($this->tmpfile, 'r');
$this->_part->setContents($data, array('stream' => true));
$this->_part->setContents($data->stream, array('stream' => true));
$this->_isBuilt = true;
}

Expand Down
9 changes: 4 additions & 5 deletions imp/lib/Compose/Attachment/Storage.php
Expand Up @@ -76,7 +76,7 @@ public function __get($name)
/**
* Read attachment data from storage.
*
* @return resource Stream containing data.
* @return Horde_Stream Stream object containing data.
* @throws IMP_Compose_Exception
*/
abstract public function read();
Expand All @@ -102,16 +102,15 @@ abstract public function write($filename, Horde_Mime_Part $part);
public function getTempFile()
{
$stream = $this->read();
rewind($stream);

$tmp = Horde::getTempFile('impatt');
$fd = fopen($tmp, 'w+');

while (!feof($stream)) {
fwrite($fd, fread($stream, 8192));
while (!$stream->eof()) {
fwrite($fd, $stream->getString(null, 8192));
}
fclose($stream);
fclose($fd);
$stream->close();

return $tmp;
}
Expand Down
13 changes: 8 additions & 5 deletions imp/lib/Compose/Attachment/Storage/Vfs.php
Expand Up @@ -58,12 +58,15 @@ public function read()
{
try {
if (method_exists($this->_vfs, 'readStream')) {
return $this->_vfs->readStream($this->_vfspath, $this->_id);
$stream = new Horde_Stream_Existing(array(
'stream' => $this->_vfs->readStream($this->_vfspath, $this->_id)
));
$stream->rewind();
} else {
$stream = new Horde_Stream_Temp();
$stream->add($this->_vfs->read($this->_vfspath, $this->_id), true);
}

$stream = new Horde_Stream_Temp();
$stream->add($this->_vfs->read($this->_vfspath, $this->_id));
return $stream->stream;
return $stream;
} catch (Horde_Vfs_Exception $e) {
throw new IMP_Compose_Exception($e);
}
Expand Down
11 changes: 4 additions & 7 deletions imp/lib/Compose/LinkedAttachment.php
Expand Up @@ -80,17 +80,14 @@ public function sendData()
}

$data = $this->_atc->read();
fseek($data, 0, SEEK_END);
$size = ftell($data);
rewind($data);

$md = $this->_atc->getMetadata();
$browser->downloadHeaders($md->filename, $md->type, false, $size);
$browser->downloadHeaders($md->filename, $md->type, false, $data->length());

while (!feof($data)) {
echo fread($data, 8192);
while (!$data->eof()) {
echo $data->getString(null, 8192);
}
fclose($data);
$data->close();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion imp/package.xml
Expand Up @@ -1350,7 +1350,7 @@
<package>
<name>Horde_Stream</name>
<channel>pear.horde.org</channel>
<min>1.0.0</min>
<min>1.4.0</min>
<max>2.0.0alpha1</max>
<exclude>2.0.0alpha1</exclude>
</package>
Expand Down

0 comments on commit 6a21150

Please sign in to comment.