PHPackages                             ksfraser/file - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. ksfraser/file

ActiveLibrary[File &amp; Storage](/categories/file-storage)

ksfraser/file
=============

File IO helpers with format-aware readers/writers (plus legacy compatibility)

0131PHP

Since Feb 14Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/ksfraser/FILE)[ Packagist](https://packagist.org/packages/ksfraser/file)[ RSS](/packages/ksfraser-file/feed)WikiDiscussions main Synced today

READMEChangelogDependenciesVersions (1)Used By (1)

Ksfraser File
=============

[](#ksfraser-file)

Format-aware file IO helpers (CSV/JSON/raw) with legacy compatibility.

Installation
------------

[](#installation)

```
composer require ksfraser/file
```

Core usage (format-aware)
-------------------------

[](#core-usage-format-aware)

```
use Ksfraser\File\FileIO;

$io = new FileIO();

// JSON by extension
$io->fput('/tmp/data.json', ['a' => 1]);
$data = $io->fget('/tmp/data.json');

// CSV by extension
$io->fput('/tmp/data.csv', [
    ['a', 'b'],
    ['1', '2'],
]);
$rows = $io->fget('/tmp/data.csv');
```

URI sanity + transports
-----------------------

[](#uri-sanity--transports)

`FileIO` selects a transport by URI scheme:

- Local files: plain paths like `C:/tmp/a.json` or `file:///C:/tmp/a.json`
- Remote reads: `http://...` and `https://...`

Remote writes are rejected.

Bytes + streams
---------------

[](#bytes--streams)

```
use Ksfraser\File\FileIO;

$io = new FileIO();

$bytes = $io->readBytes('file:///C:/tmp/a.txt');
$io->writeBytes('file:///C:/tmp/b.txt', $bytes);

$stream = $io->streamRead('https://example.com/data.json');
// $stream is typically a PSR-7 stream when guzzle is installed
```

OO wrappers (legacy-style)
--------------------------

[](#oo-wrappers-legacy-style)

```
use Ksfraser\File\KsfFile;
use Ksfraser\File\WriteFile;

$f = new KsfFile('a.txt', '/tmp');
$f->open();
$contents = $f->get_all_contents();
$f->close();

$w = new WriteFile('/tmp', 'out.txt');
$w->write_line('hello');
$w->close();
```

Legacy classes
--------------

[](#legacy-classes)

Legacy `class.*` implementations remain available under `src/Ksfraser/FileLegacy/` and are marked `@deprecated`. They are kept to avoid breaking older apps, but new development should use `Ksfraser\File\*`.

###  Health Score

20

—

LowBetter than 13% of packages

Maintenance51

Moderate activity, may be stable

Popularity7

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity12

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/c8870cc04b29a973eed9ad367a936ab274d744de37ff0c35fa0540a932905271?d=identicon)[ksfraser](/maintainers/ksfraser)

---

Top Contributors

[![ksfraser](https://avatars.githubusercontent.com/u/54461925?v=4)](https://github.com/ksfraser "ksfraser (4 commits)")

### Embed Badge

![Health badge](/badges/ksfraser-file/health.svg)

```
[![Health](https://phpackages.com/badges/ksfraser-file/health.svg)](https://phpackages.com/packages/ksfraser-file)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
