Don't load full data to determine blob size
Don't load full data to determine blob size

--- a/include/git/blob/Blob.class.php
+++ b/include/git/blob/Blob.class.php
@@ -104,6 +104,16 @@
 	}
 
 	/**
+	 * Gets whether data has been loaded
+	 *
+	 * @return boolean true if data is loaded
+	 */
+	public function DataLoaded()
+	{
+		return $this->dataRead;
+	}
+
+	/**
 	 * Set the load strategy
 	 *
 	 * @param GitPHP_BlobLoadStrategy_Interface $strategy load strategy
@@ -141,6 +151,10 @@
 	{
 		if ($this->size === null) {
 			$this->size = $this->strategy->Size($this);
+
+			foreach ($this->observers as $observer) {
+				$observer->ObjectChanged($this, GitPHP_Observer_Interface::CacheableDataChange);
+			}
 		}
 		
 		return $this->size;
@@ -169,6 +183,10 @@
 				$data = substr($data, 0, 8000);
 
 			$this->binary = (strpos($data, chr(0)) !== false);
+
+			foreach ($this->observers as $observer) {
+				$observer->ObjectChanged($this, GitPHP_Observer_Interface::CacheableDataChange);
+			}
 		}
 
 		return $this->binary;

--- a/include/git/blob/BlobLoad_Raw.class.php
+++ b/include/git/blob/BlobLoad_Raw.class.php
@@ -57,7 +57,10 @@
 		if (!$blob)
 			return;
 
-		return strlen($blob->GetData());
+		if ($blob->DataLoaded())
+			return strlen($blob->GetData());
+
+		return $this->LoadSize($blob);
 	}
 }
 

comments