Skip to content
Draft
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
36 changes: 36 additions & 0 deletions proofs/tar.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,4 +270,40 @@ static function($assert, $file) {
);
},
);

yield test(
'Tar encode files with utf8 content',
static function($assert) {
$clock = Clock::live();
$path = \rtrim(\sys_get_temp_dir(), '/').'/innmind/encoding/';
$tmp = Filesystem::mount(Path::of($path));

$file = File::named(
'._+',
File\Content::ofString('›'),
);

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

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

$exitCode = null;
\exec("tar -xf '$path/shape.tar' --directory=$path", result_code: $exitCode);
// $assert->same(0, $exitCode);

$assert->same(
$file->content()->toString(),
$tmp
->get($file->name())
->keep(Instance::of(File::class))
->match(
static fn($file) => $file->content()->toString(),
static fn() => null,
),
);
},
)->tag(\Innmind\BlackBox\Tag::wip);
};
3 changes: 3 additions & 0 deletions src/Tar/Encode.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@
->content()
->chunks()
->map(static fn($chunk) => $chunk->toEncoding(Str\Encoding::ascii))
->map(static fn($chunk) => $chunk->map(
static fn($value) => \mb_convert_encoding($value, 'UTF-8'),

Check failure on line 116 in src/Tar/Encode.php

View workflow job for this annotation

GitHub Actions / psalm / Psalm (8.3, highest) / Psalm (8.3, highest)

InvalidArgument

src/Tar/Encode.php:116:17: InvalidArgument: Argument 1 of Innmind\Immutable\Str::map expects callable(string, Innmind\Immutable\Str\Encoding):string, but pure-Closure(string):(false|string) provided (see https://psalm.dev/004)

Check failure on line 116 in src/Tar/Encode.php

View workflow job for this annotation

GitHub Actions / psalm / Psalm (8.4, lowest) / Psalm (8.4, lowest)

InvalidArgument

src/Tar/Encode.php:116:17: InvalidArgument: Argument 1 of Innmind\Immutable\Str::map expects callable(string, Innmind\Immutable\Str\Encoding):string, but pure-Closure(string):(false|string) provided (see https://psalm.dev/004)

Check failure on line 116 in src/Tar/Encode.php

View workflow job for this annotation

GitHub Actions / psalm / Psalm (8.4, highest) / Psalm (8.4, highest)

InvalidArgument

src/Tar/Encode.php:116:17: InvalidArgument: Argument 1 of Innmind\Immutable\Str::map expects callable(string, Innmind\Immutable\Str\Encoding):string, but pure-Closure(string):(false|string) provided (see https://psalm.dev/004)

Check failure on line 116 in src/Tar/Encode.php

View workflow job for this annotation

GitHub Actions / psalm / Psalm (8.2, lowest) / Psalm (8.2, lowest)

InvalidArgument

src/Tar/Encode.php:116:17: InvalidArgument: Argument 1 of Innmind\Immutable\Str::map expects callable(string, Innmind\Immutable\Str\Encoding):string, but pure-Closure(string):(false|string) provided (see https://psalm.dev/004)

Check failure on line 116 in src/Tar/Encode.php

View workflow job for this annotation

GitHub Actions / psalm / Psalm (8.3, lowest) / Psalm (8.3, lowest)

InvalidArgument

src/Tar/Encode.php:116:17: InvalidArgument: Argument 1 of Innmind\Immutable\Str::map expects callable(string, Innmind\Immutable\Str\Encoding):string, but pure-Closure(string):(false|string) provided (see https://psalm.dev/004)

Check failure on line 116 in src/Tar/Encode.php

View workflow job for this annotation

GitHub Actions / psalm / Psalm (8.2, lowest) / Psalm (8.2, lowest)

InvalidArgument

src/Tar/Encode.php:116:17: InvalidArgument: Argument 1 of Innmind\Immutable\Str::map expects callable(string, Innmind\Immutable\Str\Encoding):string, but pure-Closure(string):(false|string) provided (see https://psalm.dev/004)

Check failure on line 116 in src/Tar/Encode.php

View workflow job for this annotation

GitHub Actions / psalm / Psalm (8.3, highest) / Psalm (8.3, highest)

InvalidArgument

src/Tar/Encode.php:116:17: InvalidArgument: Argument 1 of Innmind\Immutable\Str::map expects callable(string, Innmind\Immutable\Str\Encoding):string, but pure-Closure(string):(false|string) provided (see https://psalm.dev/004)

Check failure on line 116 in src/Tar/Encode.php

View workflow job for this annotation

GitHub Actions / psalm / Psalm (8.4, lowest) / Psalm (8.4, lowest)

InvalidArgument

src/Tar/Encode.php:116:17: InvalidArgument: Argument 1 of Innmind\Immutable\Str::map expects callable(string, Innmind\Immutable\Str\Encoding):string, but pure-Closure(string):(false|string) provided (see https://psalm.dev/004)

Check failure on line 116 in src/Tar/Encode.php

View workflow job for this annotation

GitHub Actions / psalm / Psalm (8.4, highest) / Psalm (8.4, highest)

InvalidArgument

src/Tar/Encode.php:116:17: InvalidArgument: Argument 1 of Innmind\Immutable\Str::map expects callable(string, Innmind\Immutable\Str\Encoding):string, but pure-Closure(string):(false|string) provided (see https://psalm.dev/004)
))
->aggregate(static fn(Str $a, Str $b) => $a->append($b)->chunk(512))
->flatMap(static fn($str) => $str->chunk(512)) // in case there is only one line
->map(static fn($chunk) => \pack('a512', $chunk->toString()))
Expand Down
Loading