@param string      $hash
@param string      $chunk
@param string|null $context

@return bool
191667
public function addChunk(string $hash, string $chunk, ?string $context = null): bool
    {
        $this->init();
        $entity = $this->repository->findByHash($hash, $context, false);
        if ($entity) {
            $contents = $entity->getContents();
            if (is_resource($contents)) {
                $contents = stream_get_contents($contents);
            }

            $entity->setContents($contents.$chunk);

            $entity->setSize($entity->getSize() + strlen($chunk));
            $this->manager->persist($entity);
            $this->manager->flush($entity);
            return true;
        }
        return false;
    }
1356199
public function urlHash($hash = null, $withHash = true)
    {
        if ($hash) {
            $this->set('urlHash', ltrim($hash, '#'));
        }

        $hash = $this->get('urlHash', '');

        return $withHash && !empty($hash) ? '#' . $hash : $hash;
    }
342564
public function setHash($hash)
    {
        $cache = Config::getParam('cache.var', '');
        $this->hash = $hash . (strlen($cache) ? '.' : '') . $cache;
        return $this;
    }
1028947
public function isCached( string $hash ): bool
	{
		if (isset($this->cache[$hash]) == false)
			return false;

		if ($this->cache[$hash]['expires'] < time())
		{
			unset($this->cache[$hash]);
			return false;
		}

		return true;
	}
774543
public function insertChunk($chunk)
    {
        if ( ! $this->checkedIndexes) {
            $this->ensureIndexes();
        }

        $this->chunksCollection->insertOne($chunk);
    }
356802
public function finalizeUpload(string $hash, ?string $context = null): bool
    {
        return rename($this->getPath($hash, $context, false), $this->getPath($hash, $context));
    }
1313876
function reHashChunk(chunk, assets, hashFn, nameMap) {
    const isMainFile = file => file.endsWith('.js') || file.endsWith('.css');

    // Update the name of the main files
    chunk.files.filter(isMainFile).forEach((oldChunkName, index) => {
        const asset = assets[oldChunkName];
        const { fullHash, shortHash: newHash } = hashFn(asset.source());

        let newChunkName;

        if (oldChunkName.includes(chunk.renderedHash)) {
            // Save the hash map for replacing the secondary files
            nameMap[chunk.renderedHash] = newHash;
            newChunkName = oldChunkName.replace(chunk.renderedHash, newHash);

            // Keep the chunk hashes in sync
            chunk.hash = fullHash;
            chunk.renderedHash = newHash;
        } else {
            // This is a massive hack:
            //
            // The oldHash of the main file is in `chunk.renderedHash`. But some plugins add a
            // second "main" file to the chunk (for example, `mini-css-extract-plugin` adds a
            // css file). That other main file has to be rehashed too, but we don't know the
            // oldHash of the file, so we don't know what string we have to replace by the new
            // hash.
            //
            // However, the hash present in the file name must be one of the hashes of the
            // modules inside the chunk (modules[].renderedHash). So we try to replace each
            // module hash with the new hash.
            const module = Array.from(chunk.modulesIterable).find(m =>
                oldChunkName.includes(m.renderedHash)
            );

            // Can't find a module with this hash... not sure what is going on, just return and
            // hope for the best.
            if (!module) return;

            // Save the hash map for replacing the secondary files
            nameMap[module.renderedHash] = newHash;
            newChunkName = oldChunkName.replace(module.renderedHash, newHash);

            // Keep the module hashes in sync
            module.hash = fullHash;
            module.renderedHash = newHash;
        }

        // Change file name to include the new hash
        chunk.files[index] = newChunkName;
        asset._name = newChunkName;
        delete assets[oldChunkName];
        assets[newChunkName] = asset;
    });

    // Update the content of the rest of the files in the chunk
    chunk.files
        .filter(file => !isMainFile(file))
        .forEach(file => {
            Object.keys(nameMap).forEach(old => {
                const newHash = nameMap[old];
                replaceStringInAsset(assets[file], old, newHash);
            });
        });
}
332887
public function add($chunk, $fileInfo = null, $index = 0, $mapLines = null){
		$this->strs[] = $chunk;
	}
637394
public function getKeyByHash($hash)
       {
            $index = array_search($hash, $this->map, true);
            return (false === $index) ? null : $index;
       }
532743
public function setHash(string $hash): self
    {
        $this->hash = (string) hex2bin($hash);
        return $this;
    }
670082
public function flush(?string $chunk, bool $flushEmpty = false): void
	{
		if($this->isCGI)
		{
			if(!empty($chunk))
			{
				echo $chunk;

				flush();
			}
		}
		else
		{
			if(!empty($chunk) || $flushEmpty === true)
			{
				printf("%x\r\n%s\r\n", strlen($chunk), $chunk);

				flush();
			}
		}
	}
560911
public function is_file_readable_remotely_by_hash($contenthash) {
        if ($contenthash === file_storage::hash_from_string('')) {
            // Files with empty size are either directories or empty.
            // We handle these virtually.
            return true;
        }

        $path = $this->get_remote_path_from_hash($contenthash, false);

        // Note - it is not possible to perform a content recovery safely from a hash alone.
        return is_readable($path);
    }
449257
private function _returnHash(string $hash, int $length)
    {
        try {
            return substr($hash, 0, $length);
        } catch (\Exception $e) { }

        return false;
    }
102976
public boolean lockContextLocally(ChronicleHash<?, ?, ?, ?> hash) {
        // hash().isOpen() check guarantees no starvation of a thread calling chMap.close() and
        // trying to close this context by closeContext() method below, while the thread owning this
        // context frequently locks and unlocks it (e. g. in a loop). This is also the only check
        // for chMap openness during the whole context usage lifecycle.
        if (hash.isOpen() && MEMORY.compareAndSwapInt(this, CONTEXT_LOCK_OFFSET,
                CONTEXT_UNLOCKED, CONTEXT_LOCKED_LOCALLY)) {
            return true;
        } else {
            if (contextLock == CONTEXT_LOCKED_LOCALLY)
                return false;
            // Don't extract this hash().isOpen() and the one above, because they could return
            // different results: the first (above) could return true, the second (below) - false.
            if (contextLock == CONTEXT_CLOSED || !hash.isOpen())
                throw new ChronicleHashClosedException(hash);
            throw new AssertionError("Unknown context lock state: " + contextLock);
        }
    }
1057370
public function destroy($hash = null)
    {
        // If the hash is not received, get it from the request
        $hash = $hash?: $this->app->request->token();

        // Abort if the file does not exist
        $path = $this->path($hash);
        if (!file_exists($path)) {
            return true;
        }

        // Otherwise, remove the token file
        $success = unlink($path);
        if (!$success) {
            throw new Exception("The session could not be erased", 500);
        }

        // Return success
        return $success;
    }
805792
public function init($chunk = null) {
        if (is_null($chunk) && is_null($chunk = $this->_getCurrentStateFromRequest())) {
            $chunk = 1;
        }
        if ($chunk < 1) {
            $chunk = 1;
        }
        $this->_chunk   = $chunk;
        $this->_results = $this->_fetchContent($chunk);
        $this->_max = $this->_fetchMaxChunks();
        return $this;
    }
814777
public function decode($hash)
    {
        $volume = $this->bridge->getVolume($hash);

        /* @var $volume \elFinderVolumeDriver */
        return (!empty($volume)) ? $volume->getPath($hash) : false;
    }