Interfaces
3 weeks ago
trait-bufferedwritestreamviaputcontents.php
3 weeks ago
trait-copydirectoryrecursive.php
3 weeks ago
trait-copyfileviastreaming.php
3 weeks ago
trait-copyrecursiveviastreaming.php
3 weeks ago
trait-getcontentsviareadstream.php
3 weeks ago
trait-internalizewritestream.php
3 weeks ago
trait-mkdirrecursive.php
3 weeks ago
trait-putcontentsviawritestream.php
3 weeks ago
trait-readonlyfilesystem.php
3 weeks ago
trait-renamefileviacopyandrm.php
3 weeks ago
trait-rmdirrecursive.php
3 weeks ago
trait-internalizewritestream.php
37 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WordPress\Filesystem\Mixin; |
| 4 | |
| 5 | use WordPress\ByteStream\WriteStream\ByteWriteStream; |
| 6 | use WordPress\Filesystem\ByteStream\FilesystemWriteStream; |
| 7 | |
| 8 | trait InternalizeWriteStream { |
| 9 | |
| 10 | /** |
| 11 | * Start streaming a file. |
| 12 | * |
| 13 | * @param string $path The path to the file. |
| 14 | * |
| 15 | * @return ByteWriteStream The stream. |
| 16 | * @example |
| 17 | * |
| 18 | * $fs->open_read_stream($path); |
| 19 | * while($fs->next_file_chunk()) { |
| 20 | * $chunk = $fs->get_file_chunk(); |
| 21 | * // process $chunk |
| 22 | * } |
| 23 | * $fs->close_read_stream(); |
| 24 | */ |
| 25 | public function open_write_stream( $path ): ByteWriteStream { |
| 26 | $stream_id = $this->write_stream_internal_open( $path ); |
| 27 | |
| 28 | return new FilesystemWriteStream( $this, $stream_id ); |
| 29 | } |
| 30 | |
| 31 | abstract protected function write_stream_internal_open( string $path ): int; |
| 32 | |
| 33 | abstract public function write_stream_append_bytes( int $stream_id, $data ); |
| 34 | |
| 35 | abstract public function write_stream_close( int $stream_id ); |
| 36 | } |
| 37 |