Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,3 @@ jobs:
uses: innmind/github-workflows/.github/workflows/psalm-matrix.yml@main
cs:
uses: innmind/github-workflows/.github/workflows/cs.yml@main
with:
php-version: '8.2'
12 changes: 12 additions & 0 deletions .github/workflows/extensive.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Extensive CI

on:
push:
tags:
- '*'
paths:
- '.github/workflows/extensive.yml'

jobs:
blackbox:
uses: innmind/github-workflows/.github/workflows/extensive.yml@main
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## [Unreleased]

### Changed

- Requires PHP `8.4`
- Requires `innmind/filesystem:~9.0`
- Requires `innmind/time:~1.0`

## 2.0.0 - 2025-04-16

### Changed
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ composer require innmind/encoding

```php
use Innmind\Filesystem\{
Adapter\Filesystem,
Adapter,
Name,
};
use Innmind\TimeContinuum\Clock;
use Innmind\Time\Clock;
use Innmind\Url\Path;
use Innmind\Encoding\{
Gzip,
Tar,
};

$adapter = Filesystem::mount(Path::of('some/directory/'));
$adapter = Adapter::mount(Path::of('some/directory/'))->unwrap();
$tar = $adapter
->get(Name::of('data'))
->map(Tar::encode(Clock::live()))
Expand Down
4 changes: 4 additions & 0 deletions blackbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
};

Application::new($argv)
->when(
\getenv('BLACKBOX_SET_SIZE') !== false,
static fn(Application $app) => $app->scenariiPerProof((int) \getenv('BLACKBOX_SET_SIZE')),
)
->when(
\getenv('ENABLE_COVERAGE') !== false,
static fn(Application $app) => $app
Expand Down
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@
"issues": "http://github.com/innmind/encoding/issues"
},
"require": {
"php": "~8.2",
"innmind/immutable": "~5.7",
"innmind/filesystem": "~8.0",
"innmind/time-continuum": "~4.1"
"php": "~8.4",
"innmind/immutable": "~6.0",
"innmind/filesystem": "~9.0",
"innmind/time": "~1.0"
},
"autoload": {
"psr-4": {
"Innmind\\Encoding\\": "src/"
}
},
"require-dev": {
"innmind/static-analysis": "^1.2.1",
"innmind/black-box": "~6.1",
"innmind/static-analysis": "~1.3",
"innmind/black-box": "~6.9",
"innmind/coding-standard": "~2.0"
}
}
10 changes: 7 additions & 3 deletions documentation/use-cases/backup.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@ $os = Factory::build();
$data = $os
->filesystem()
->mount(Path::of('path/to/stored/data'))
->unwrap()
->root()
->rename(Name::of('data'));
$sql = $os->remote()->sql(Url::of('mysql://{user}:{password}@localhost:3306/{database}'));
$sql = $os
->remote()
->sql(Url::of('mysql://{user}:{password}@localhost:3306/{database}'))
->unwrap();
$users = $sql(SQL::onDemand('SELECT * FROM users'))
->map(static fn($row) => \implode(
"\t",
Expand All @@ -53,7 +57,7 @@ Up to this point `$archive` represents a file content but no real operation has

```php
use Innmind\Http\{
ResponseSender,
Response\Sender\Native as ResponseSender,
Response,
Response\StatusCode,
ProtocolVersion,
Expand All @@ -63,7 +67,7 @@ use Innmind\Http\{

$archive = /* see above */;

(new ResponseSender($os->clock()))(Response::of(
ResponseSender::of($os->clock())(Response::of(
StatusCode::ok,
ProtocolVersion::v11,
Headers::of(
Expand Down
15 changes: 9 additions & 6 deletions documentation/use-cases/compressed-at-rest.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use Innmind\Url\Path;
use Innmind\Http\{
Response,
Response\StatusCode,
ResponseSender,
Response\Sender\Native as ResponseSender,
};

$os = Factory::build();
Expand All @@ -25,14 +25,16 @@ $response = $serverRequest
->files()
->under('tsv')
->get('users')
->map(static fn($file) => $file->content()
->map(static fn($file) => $file->content())
->map(Gzip::compress())
->map(static fn($content) => File::named('users.tsv.gz', $content))
->map(
static fn($file) => $os
->filesystem()
->mount(Path::of('path/to/stored/data/'))
->add($file)),
->unwrap()
->add($file)
->unwrap(),
)
->match(
static fn() => Response::of(
Expand All @@ -45,7 +47,7 @@ $response = $serverRequest
),
);

(new ResponseSender($os->clock()))($response);
ResponseSender::of($os->clock())($response);
```

This code will take any file uploaded in the key `tsv[users]`, gzip it and write it in the `path/to/stored/data/` directory under the name `users.tsv.gz` and return a `201` HTTP response. If the upload failed it will return a `400` response.
Expand All @@ -61,7 +63,7 @@ use Innmind\Url\Path;
use Innmind\Http\{
Response,
Response\StatusCode,
ResponseSender,
Response\Sender\Native as ResponseSender,
Headers,
Header\ContentType,
Header\ContentEncoding,
Expand All @@ -84,6 +86,7 @@ $acceptGzip = $serverRequest
$response = $os
->filesystem()
->mount(Path::of('path/to/stored/data/'))
->unwrap()
->get(Name::of('users.tsv.gz'))
->map(static fn($file) => match ($acceptGzip) {
true => Response::of(
Expand Down Expand Up @@ -112,7 +115,7 @@ $response = $os
),
);

(new ResponseSender($os->clock()))($response);
ResponseSender::of($os->clock())($response);
```

Here we try to load the `users.tsv.gz` file, we check if the caller accepts a gzipped content, if so we return the file as is via a `200` HTTP response and if not we decompress the file and return it. And if the file doesn't exist we return a `400` response.
1 change: 1 addition & 0 deletions documentation/use-cases/http.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ $http = $os->remote()->http();
$os
->filesystem()
->mount(Path::of('path/to/stored/data/'))
->unwrap()
->get(Name::of('somefile.txt'))
->map(static fn($file) => $file->content());
->map(Gzip::compress())
Expand Down
8 changes: 4 additions & 4 deletions proofs/gzip.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ static function($assert, $file) {
->number(
$content
->chunks()
->fold(new Concat)
->fold(Concat::monoid)
->toEncoding(Encoding::ascii)
->length(),
)
->greaterThan(
$compressed
->chunks()
->fold(new Concat)
->fold(Concat::monoid)
->toEncoding(Encoding::ascii)
->length(),
);
Expand Down Expand Up @@ -98,8 +98,8 @@ static function($assert, $file) {
$content = $decompress($compress($original));

$assert->same(
$original->chunks()->fold(new Concat)->toString(),
$content->chunks()->fold(new Concat)->toString(),
$original->chunks()->fold(Concat::monoid)->toString(),
$content->chunks()->fold(Concat::monoid)->toString(),
);
},
);
Expand Down
45 changes: 30 additions & 15 deletions proofs/tar.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@

use Innmind\Encoding\Tar;
use Innmind\Filesystem\{
Adapter\Filesystem,
Adapter,
Name,
File,
Directory,
Recover,
};
use Innmind\TimeContinuum\Clock;
use Innmind\Time\Clock;
use Innmind\Url\Path;
use Innmind\Immutable\{
Str,
Expand All @@ -27,8 +28,12 @@
static function($assert, $name) {
$clock = Clock::live();
$path = \rtrim(\sys_get_temp_dir(), '/').'/innmind/encoding/';
$tmp = Filesystem::mount(Path::of($path));
$adapter = Filesystem::mount(Path::of('fixtures/'));
$tmp = Adapter::mount(Path::of($path))
->recover(Recover::mount(...))
->unwrap();
$adapter = Adapter::mount(Path::of('fixtures/'))
->recover(Recover::mount(...))
->unwrap();
$tar = $adapter
->get(Name::of($name))
->map(static fn($file) => $file->rename(Name::of('other-'.$name)))
Expand All @@ -39,7 +44,7 @@ static function($assert, $name) {
);
$tar = File::named('test.tar', $tar);

$tmp->add($tar);
$_ = $tmp->add($tar)->unwrap();

$exitCode = null;
\exec("tar -xf $path/test.tar --directory=$path", result_code: $exitCode);
Expand Down Expand Up @@ -67,8 +72,12 @@ static function($assert, $name) {
static function($assert) {
$clock = Clock::live();
$path = \rtrim(\sys_get_temp_dir(), '/').'/innmind/encoding/';
$tmp = Filesystem::mount(Path::of($path));
$adapter = Filesystem::mount(Path::of('./'));
$tmp = Adapter::mount(Path::of($path))
->recover(Recover::mount(...))
->unwrap();
$adapter = Adapter::mount(Path::of('./'))
->recover(Recover::mount(...))
->unwrap();
$tar = $adapter
->get(Name::of('fixtures'))
->map(Tar::encode($clock))
Expand All @@ -79,7 +88,7 @@ static function($assert) {

$tar = File::named('fixtures.tar', $tar);

$tmp->add($tar);
$_ = $tmp->add($tar)->unwrap();

$exitCode = null;
\exec("tar -xf $path/fixtures.tar --directory=$path", result_code: $exitCode);
Expand Down Expand Up @@ -142,8 +151,12 @@ static function($assert, $name1, $name2) {

$clock = Clock::live();
$path = \rtrim(\sys_get_temp_dir(), '/').'/innmind/encoding/';
$tmp = Filesystem::mount(Path::of($path));
$adapter = Filesystem::mount(Path::of('./'));
$tmp = Adapter::mount(Path::of($path))
->recover(Recover::mount(...))
->unwrap();
$adapter = Adapter::mount(Path::of('./'))
->recover(Recover::mount(...))
->unwrap();
$tar = $adapter
->get(Name::of('fixtures'))
->map(Directory::of($name2)->add(...))
Expand All @@ -156,7 +169,7 @@ static function($assert, $name1, $name2) {

$tar = File::named('names.tar', $tar);

$tmp->add($tar);
$_ = $tmp->add($tar)->unwrap();

$exitCode = null;
\exec("tar -xf $path/names.tar --directory=$path", result_code: $exitCode);
Expand Down Expand Up @@ -221,14 +234,16 @@ static function($assert, $name1, $name2) {
static function($assert, $file) {
$clock = Clock::live();
$path = \rtrim(\sys_get_temp_dir(), '/').'/innmind/encoding/';
$tmp = Filesystem::mount(Path::of($path));
$tmp = Adapter::mount(Path::of($path))
->recover(Recover::mount(...))
->unwrap();

// make sure to avoid conflicts when trying to unarchive
$tmp->remove($file->name());
$_ = $tmp->remove($file->name())->unwrap();

$tar = Tar::encode($clock)($file);
$tar = File::named('shape.tar', $tar);
$tmp->add($tar);
$_ = $tmp->add($tar)->unwrap();

$exitCode = null;
\exec("tar -xf '$path/shape.tar' --directory=$path", result_code: $exitCode);
Expand All @@ -251,7 +266,7 @@ static function($assert, $file) {

$assert->true($tmp->contains($file->name()));
// for simplicity no recursive assertions on nested directories
$file
$_ = $file
->all()
->keep(Instance::of(File::class))
->foreach(
Expand Down
2 changes: 1 addition & 1 deletion src/Tar.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Innmind\Encoding;

use Innmind\TimeContinuum\Clock;
use Innmind\Time\Clock;

final class Tar
{
Expand Down
2 changes: 1 addition & 1 deletion src/Tar/Encode.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
File\Content,
Directory,
};
use Innmind\TimeContinuum\{
use Innmind\Time\{
Clock,
Format,
};
Expand Down