mirror of
https://codeberg.org/icewind/SMB.git
synced 2026-06-04 01:34:07 +02:00
use a string based buffer for Read/Write streams
This commit is contained in:
parent
866f2b19a6
commit
0d9341c527
6 changed files with 184 additions and 38 deletions
|
|
@ -7,22 +7,21 @@
|
|||
|
||||
namespace Icewind\SMB\Native;
|
||||
|
||||
use Icewind\SMB\StringBuffer;
|
||||
|
||||
/**
|
||||
* Stream optimized for write only usage
|
||||
*/
|
||||
class NativeWriteStream extends NativeStream {
|
||||
const CHUNK_SIZE = 1048576; // 1MB chunks
|
||||
/**
|
||||
* @var resource
|
||||
*/
|
||||
private $writeBuffer = null;
|
||||
|
||||
private $bufferSize = 0;
|
||||
/** @var StringBuffer */
|
||||
private $writeBuffer;
|
||||
|
||||
private $pos = 0;
|
||||
|
||||
public function stream_open($path, $mode, $options, &$opened_path) {
|
||||
$this->writeBuffer = fopen('php://memory', 'r+');
|
||||
$this->writeBuffer = new StringBuffer();
|
||||
|
||||
return parent::stream_open($path, $mode, $options, $opened_path);
|
||||
}
|
||||
|
|
@ -60,18 +59,14 @@ class NativeWriteStream extends NativeStream {
|
|||
}
|
||||
|
||||
private function flushWrite() {
|
||||
rewind($this->writeBuffer);
|
||||
$this->state->write($this->handle, stream_get_contents($this->writeBuffer), $this->url);
|
||||
$this->writeBuffer = fopen('php://memory', 'r+');
|
||||
$this->bufferSize = 0;
|
||||
$this->state->write($this->handle, $this->writeBuffer->flush(), $this->url);
|
||||
}
|
||||
|
||||
public function stream_write($data) {
|
||||
$written = fwrite($this->writeBuffer, $data);
|
||||
$this->bufferSize += $written;
|
||||
$written = $this->writeBuffer->push($data);
|
||||
$this->pos += $written;
|
||||
|
||||
if ($this->bufferSize >= self::CHUNK_SIZE) {
|
||||
if ($this->writeBuffer->remaining() >= self::CHUNK_SIZE) {
|
||||
$this->flushWrite();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue