X-Git-Url: https://git.mxchange.org/?p=core.git;a=blobdiff_plain;f=inc%2Fclasses%2Fmain%2Ffile_directories%2Fbinary%2Fstack%2Fclass_StackFile.php;h=cf562b8766b4cae87952bf597056692508c9c744;hp=95eb82a72c0b82c2f9fd7650b784dfb56f3d0dbd;hb=bde1a7331a8a5c1e4a304583c0db268026aeb8a8;hpb=ce7d4f1ec37db463e6008655bbc56b811c5a5d86 diff --git a/inc/classes/main/file_directories/binary/stack/class_StackFile.php b/inc/classes/main/file_directories/binary/stack/class_StackFile.php index 95eb82a7..cf562b87 100644 --- a/inc/classes/main/file_directories/binary/stack/class_StackFile.php +++ b/inc/classes/main/file_directories/binary/stack/class_StackFile.php @@ -52,6 +52,45 @@ class StackFile extends BaseBinaryFile implements Block { // Return the prepared instance return $fileInstance; } + + /** + * Writes given value to the file and returns a hash and gap position for it + * + * @param $groupId Group identifier + * @param $value Value to be added to the stack + * @return $data Hash and gap position + */ + public function writeValueToFile ($groupId, $value) { + // Make sure no objects/resources are added as the serialization may fail + assert(!is_object($value)); + assert(!is_resource($value)); + + // Encode/convert the value into a "binary format" + $encoded = $this->encodeData($value); + + // Get a strong hash for the "encoded" data + $hash = self::hash($encoded); + + // Then write it to the next free gap + $data = $this->getBlockInstance()->writeDataToFreeGap($groupId, $hash, $encoded); + + // Return info + return $data; + } + + /** + * Writes given raw data to the file and returns a gap position and length + * + * @param $groupId Group identifier + * @param $hash Hash from encoded value + * @param $encoded Encoded value to be written to the file + * @return $data Gap position and length of the raw data + * @throws UnsupportedOperationException If this method is called + */ + public function writeDataToFreeGap ($groupId, $hash, $encoded) { + self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . '] groupId=' . $groupId . ',hash=' . $hash . ',encoded()=' . strlen($encoded)); + throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION); + } } // [EOF]