承接 atk14/string-buffer 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

atk14/string-buffer

Composer 安装命令:

composer require atk14/string-buffer

包简介

StringBuffer is a PHP class providing operations for efficient string buffering

README 文档

README

Tests

StringBuffer is a PHP class providing operations for efficient string buffering. It can hold a mix of plain strings and file contents, and treats them uniformly as a single continuous buffer.

Installation

composer require atk14/string-buffer

Basic usage

$sb = new StringBuffer();
$sb->addString("Hello World!\n");
$sb->addString(" How are you?");
$sb->addFile("/path/to/file");

$length = $sb->getLength();
$sb->printOut();

You can also pass an initial string to the constructor:

$sb = new StringBuffer("Hello World!");

Combining buffers:

$sb1 = new StringBuffer("Hello");
$sb2 = new StringBuffer(" World!");
$sb1->addStringBuffer($sb2);
echo $sb1; // "Hello World!"

Converting to string:

$string = (string)$sb;
// or
$string = "$sb";
// or
$string = $sb->toString();

Other operations:

// Replace a substring throughout the buffer
$sb->replace("World", "PHP");

// Extract a portion of the buffer (works like PHP's substr())
$part = $sb->substr(0, 5);
$last = $sb->substr(-3);

// Write the whole buffer to a file
$sb->writeToFile("/path/to/output.dat");

// Clear the buffer
$sb->clear();

Memory-efficient temporary buffer

StringBufferTemporary is a drop-in replacement for StringBuffer that automatically offloads content to a temporary file once it exceeds 1 MB. This keeps memory consumption low when working with large amounts of data.

$buffer = new StringBufferTemporary();

$buffer->add($megabyte);
$buffer->add($megabyte);
$buffer->add($megabyte);

$buffer->printOut();
// or
$buffer->writeToFile($target_filename);

Temporary files are created automatically and deleted when the buffer object is destroyed.

The threshold can be adjusted if needed:

StringBufferTemporary::$FILEIZE_THRESHOLD = 512 * 1024; // 512 kB

The temporary directory defaults to the system temp dir. To override it, define the TEMP constant before using the class:

define("TEMP", "/path/to/temp/");

Append buffer contents to the file

The file opening mode can be passed as the second parameter of the writeToFile() method.

// Write at the end of the file
$buffer->writeToFile("/path/to/output.dat","a"); 

Licence

StringBuffer is free software distributed under the terms of the MIT license

统计信息

  • 总下载量: 31.17k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 5
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-01-24

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固