[pLog-svn] r2374 - in plog/branches/plog-1.0.2/class: gallery/dao
view
oscar at devel.plogworld.net
oscar at devel.plogworld.net
Thu Jul 28 09:43:33 GMT 2005
Author: oscar
Date: 2005-07-28 09:43:32 +0000 (Thu, 28 Jul 2005)
New Revision: 2374
Modified:
plog/branches/plog-1.0.2/class/gallery/dao/galleryresource.class.php
plog/branches/plog-1.0.2/class/view/resourceserverview.class.php
Log:
added matt's patch to load the resource data in chunks instead of going through
memory and then dumping it to the client.
Modified: plog/branches/plog-1.0.2/class/gallery/dao/galleryresource.class.php
===================================================================
--- plog/branches/plog-1.0.2/class/gallery/dao/galleryresource.class.php 2005-07-28 09:31:55 UTC (rev 2373)
+++ plog/branches/plog-1.0.2/class/gallery/dao/galleryresource.class.php 2005-07-28 09:43:32 UTC (rev 2374)
@@ -39,6 +39,7 @@
var $_metadata;
var $_album;
var $_thumbnailFormat;
+ var $_fileDescriptor;
/**
* Constructor.
@@ -80,6 +81,7 @@
$this->_date = $date;
$this->_thumbnailFormat = $thumbnailFormat;
$this->_id = $id;
+ $this->_fileDescriptor = false;
}
/**
@@ -212,6 +214,49 @@
return $this->_getData( $fileName );
}
+
+ /**
+ * returns a buffer of bytes limited to $chunkSize in bytes from
+ * the file descriptor provided
+ *
+ * @return a buffer of bytes from the file or false if empty or error
+ */
+ function &_getDataChunk(&$filedesc,$chunkSize)
+ {
+ if (feof($filedesc) || !$filedesc)
+ {
+ /* finished reading file */
+ if (feof($filedesc))
+ fclose($filedesc);
+
+ return false;
+ }
+ else
+ {
+ /* return $chunksize of bytes */
+ return fread($filedesc,$chunkSize);
+ }
+ }
+
+ function &getDataChunk($chunksize)
+ {
+ if (!$this->_fileDescriptor)
+ {
+ $fileParts = explode(".",$this->getFileName());
+ $fileExt = $fileParts[count($fileParts)-1];
+ $resourceStorageFolder =
+ GalleryResourceStorage::getResourcesStorageFolder();
+ $fileName = $resourceStorageFolder.$this->getOwnerId().
+ "/".$this->getOwnerId()."-".$this->getId().".".$fileExt;
+
+ /* store this for use again */
+ $this->_fileDescriptor = @fopen($fileName,"rb");
+ /* open failed... we'll just say empty file */
+ if (!$this->_fileDescriptor)
+ return false;
+ }
+ return $this->_getDataChunk(&$this->_fileDescriptor,$chunksize);
+ }
/**
* Sets the album id. You should normally not need to use this method
Modified: plog/branches/plog-1.0.2/class/view/resourceserverview.class.php
===================================================================
--- plog/branches/plog-1.0.2/class/view/resourceserverview.class.php 2005-07-28 09:31:55 UTC (rev 2373)
+++ plog/branches/plog-1.0.2/class/view/resourceserverview.class.php 2005-07-28 09:43:32 UTC (rev 2374)
@@ -8,6 +8,7 @@
define( 'RESOURCE_VIEW_MODE_PREVIEW', 'preview' );
define( 'RESOURCE_VIEW_MODE_MEDIUM', 'medium' );
define( 'DEFAULT_HTTP_CACHE_LIFETIME', '86400');
+ define( 'RESOURCE_DEFAULT_CHUNK_SIZE', '32768' );
/**
* \ingroup View
@@ -97,7 +98,8 @@
elseif( $this->_mode == RESOURCE_VIEW_MODE_MEDIUM )
print( $this->_resource->getMediumSizePreview());
else {
- print( $this->_resource->getData());
+ while($chunk =& $this->_resource->getDataChunk( RESOURCE_DEFAULT_CHUNK_SIZE ))
+ echo( $chunk );
}
return true;
More information about the pLog-svn
mailing list