General storage function

@param string $data binary data to prepend
@access private
498442
function _prepend($data)
    {
        if (strlen($data) > $this->_limit) {
            $data = $this->_addContinue($data);
        }
        $this->_data      = $data.$this->_data;
        $this->_datasize += strlen($data);
    }
1028049
private function prepareContent($data)
    {
        $content = '';

        foreach ($data as $row) {
            $content .= $this->convertToJson($row) . static::ROW_DELIMITER;
        }

        return $content;
    }
1369318
public function writeBytes($data)
    {
        if ($this->isClosed) {
            // TODO: Should this be an error condition? e.g. BadMethodCallException
            return;
        }

        $bytesRead = 0;

        while ($bytesRead != strlen($data)) {
            $initialBufferLength = strlen($this->buffer);
            $this->buffer .= substr($data, $bytesRead, $this->chunkSize - $initialBufferLength);
            $bytesRead += strlen($this->buffer) - $initialBufferLength;

            if (strlen($this->buffer) == $this->chunkSize) {
                $this->insertChunkFromBuffer();
            }
        }

        return $bytesRead;
    }
52910
protected function convert($data)
    {
        foreach ($data[0] as $key => $value) {
            if (!$this->_kept && !$this->_stashed) {
                $this->$key = $value;
                $this->setKey($key, $value);
            } else {
                if ($this->_kept) {
                    $this->_keptData[$key] = $value;
                }
                if ($this->_stashed) {
                    $this->_stashedData[$key] = $value;
                }
            }

            $this->data[$key] = $value;
        }
    }
1350624
public function putBack($data)
    {
        if (TStringFuncFactory::create()->strlen($this->rBuf_) === 0) {
            $this->rBuf_ = $data;
        } else {
            $this->rBuf_ = ($data . $this->rBuf_);
        }
    }
159981
public function append($data) {

		if(false === is_string($data)) {
			return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($data)), E_USER_ERROR);
		}

		if(false !== $this -> file -> getExists()) {

	    	if(false === is_writable($this -> file -> getBasepath())) {
	    		trigger_error(sprintf('File "%s" is not writable', $this -> file -> getBasepath()), E_USER_ERROR);
	    	}

		    $handle = fopen($this -> file -> getBasepath(), 'a');

	    	fwrite($handle, $data);
	    	fclose($handle);
		}

		return $this;
	}
1083462
function prependLength(data) {
	const lengthAsBytes = buffer.Buffer.alloc(4);

	lengthAsBytes.writeUInt32BE(data.length);

	return buffer.Buffer.concat([lengthAsBytes, data]);
}
526480
public function write($data)
    {
        $dataLength     = strlen($data);
        $start          = substr($this->buffer, 0, $this->position);
        $end            = substr($this->buffer, $this->position + $dataLength);
        $this->buffer   = $start.$data.$end;
        $this->length   = strlen($this->buffer);
        $this->position += $dataLength;
        return $dataLength;
    }
1166919
public function persist($data = null)
    {
        if (is_null($data)) {
            $data = $this->database->toArray();
        }

        if (! is_array($data)) {
            $data = $data->toArray();
        }

        $this->makeDir($this->getFileName());

        file_put_contents($this->getFileName(), json_encode($data));
    }
479376
public function prepend($path, $data)
    {
        return $this->filesystem->prepend(
            $this->path($path),
            $data
        );
    }
1258312
public function unserialize($data)
    {
        $vars = unserialize($data);
        foreach ($vars as $var => $value) {
            $this->{$var} = $value;
        }
    }
916325
public function load($data)
    {
        // Turn current string into an array using provided separator
        $values = explode(',', $data);

        // If empty string is passed, then explode() returns false
        if ($values === false) {
            $values = array();
        } else {
            // Remove empty values from current array we have
            array_walk($values, function($value, $key) use (&$values) {
                if (empty($value)) {
                    unset($values[$key]);
                }
            });
        }

        // Done
        $this->values = $values;
    }
1150096
public static function prepend(string $file, $data, bool $lock = false)
	{
		return file_put_contents($file, $data . file_get_contents($file), $lock ? LOCK_EX : 0);
	}
316022
public function appendSerialized($data)
    {
        try {
            $data = Serializer::unserialize($data);
        } catch (ExceptionInterface $exception) {
            $this->_addException($exception);
        }

        if (is_object($data)) {
            $name = $this->_convertKeyNames(get_class($data));
            $this->appendData($name, $data);
        } elseif (is_array($data)) {
            $this->appendArray($data);
        } else {
            $this->appendData($this->_defaultDataName, $data);
        }

        if ($this->_objectCreation) {
            return $this->_afterAppendDataToNewObject();
        }
        return $this;
    }
1324206
public function bufferWrite(string $data): Promise
    {
        if ($this->append_after) {
            $this->append_after -= strlen($data);
            if ($this->append_after === 0) {
                $data .= $this->append;
                $this->append = '';
            } elseif ($this->append_after < 0) {
                $this->append_after = 0;
                $this->append = '';

                throw new Exception('Tried to send too much out of frame data, cannot append');
            }
        }

        return $this->write_buffer->bufferWrite(@$this->encrypt->encrypt($data));
    }
265598
public function write($data)
    {
        //encrypt the data if needed
        if($this->secret !== null) {
            mcrypt_generic_init($this->encryptor, $this->secret, $this->secret);
            $data = mcrypt_generic($this->encryptor, $data);
            mcrypt_generic_deinit($this->encryptor);
        }
        return parent::write($data);
    }
509014
function put($data)
    {
        if ($this->_change == self::STATE_INSERT)
        {
            $this->_change = self::STATE_UPDATE;
            $this->_update = $data;
        }
        elseif ($this->_change == self::STATE_EMPTY)
        {
            $this->_change = self::STATE_INSERT;
            $this->_data = $data;
        }
    }