定制 carloshlfz/php-grf 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

carloshlfz/php-grf

最新稳定版本:0.1.56

Composer 安装命令:

composer require carloshlfz/php-grf

包简介

GRF Lib for read and write in PHP.

README 文档

README

This is a lib to allow PHP to read and write GRF (Gravity Ragnarok Files).

Build Status

Build Status Build status issues pull-request

Code Quality

CodeFactor Codacy Badge

Code Coverage

codecov Codacy Badge

How i can colaborate?

Please! check our issues and if you can fix or add new features, you're welcome.

Also, see if what you're about to change is in ours pull requests.

How to open a file to read?

The code ahead, will show you how to extract all files inside grf.

<?php
require_once 'php-grf/lib/autoload.php';

// Instance a reader/writer for your grf file
$grf = new GrfFile('php-grf/tests/test200.grf');

foreach ($grf->getEntries() as $entry) {
    $dir = dirname($entry->getFilename());

    if (is_dir($dir) === false)
        mkdir ($dir, 0777, true);

    $file = str_replace('\\', '/', $entry->getFilename());
    $buffer = $entry->getUnCompressedBuffer();

    $fp = fopen($file, 'wb');
    fwrite($fp, $buffer);
    fflush($fp);
    fclose($fp);
}

// Dispose all resources used
$grf = null;

If you wanna search inside entries:

<?php
require_once 'php-grf/lib/autoload.php';

// Instance a reader/writer for your grf file
$grf = new GrfFile('php-grf/tests/test200.grf');

// Find all files in entries (including added)
// when uncompressed the size is more then 1000 bytes.
$search = $grf->getEntries()->where(function($entry) {
	return $entry->getUnCompressedSize() > 1000;
});

// Dispose all resources used
$grf = null;

Know the full path inside grf the file is?

<?php
require_once 'php-grf/lib/autoload.php';

// Instance a reader/writer for your grf file
$grf = new GrfFile('php-grf/tests/test200.grf');
$entries = $grf->getEntries();
$entry = $entries['data\\0_Tex1.bmp'];

if ($entry === null) { // not found

}

// Dispose all resources used
$grf = null;

How to open a grf file to write?

The same way you open to read, you can write. See:

require_once 'php-grf/lib/autoload.php';

// Instance a reader/writer for your grf file
$grf = new GrfFile('php-grf/tests/test200.grf');

$grf->addFile('file-outside.txt', 'data\\file-inside.txt');

// Dispose all resources used
$grf->close(); // Auto save when closed
$grf = null;

When you call $grf->save() or $grf->close() this'll repack your grf. Large grf files may take some minutes to finish.

How to create a grf file to write?

Look here how to create a new grf file:

require_once 'php-grf/lib/autoload.php';

// Creates a new grf file with no files inside
$grf = GrfFile::create('your-grf-file.grf');

// Dispose all resources used
$grf->close(); // Auto save when closed
$grf = null;

To add files, just check the section above...

Install

To install, you only need use composer require to use.

composer require carloshlfz/php-grf

Just make sure you've vendor/autoload.php loaded and is just start to use.

Credits and other infos

The grf file inside tests folder test200.grf is from arminherling/GRF.

This code is based on MagicalTux/grf

统计信息

  • 总下载量: 521
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 17
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 17
  • Watchers: 2
  • Forks: 6
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2019-02-26