Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement a limited in-memory buffer with filesystem overflow #343

Merged
merged 6 commits into from
Jun 23, 2024

Conversation

thekid
Copy link
Member

@thekid thekid commented Jun 22, 2024

Example:

use io\streams\Buffer;
use lang\Environment;

$buffer= new Buffer(Environment::tempDir(), 1024);

// This will be written to memory as it's shorter than the threshold
$buffer->write('Slice #1');

// With this write, the buffer exceeds the threshold and is thus saved to a file
$buffer->write(str_repeat('*', 2048)); 

// Drain the buffer
while ($buffer->available()) {
  $chunk= $buffer->read();
}

// Close the buffer, removing the file created by the second write
$buffer->close();

Inspired by xp-forge/web#118

@thekid thekid merged commit 25a4366 into xp-framework:main Jun 23, 2024
13 checks passed
@thekid thekid deleted the feature/io-buffer branch June 23, 2024 07:34
@thekid
Copy link
Member Author

thekid commented Jun 23, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant