Skip to content

Use push strategy to create temporary file to avoid throwing exceptions #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 18, 2025
Merged
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
32 changes: 16 additions & 16 deletions src/Filesystem/Generic.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,22 +115,22 @@ public function watch(Path $path): Ping
#[\Override]
public function temporary(Sequence $chunks): Attempt
{
return Attempt::of(
fn() => $this
->config
->io()
->files()
->temporary(
$chunks->map(
static fn($chunk) => $chunk
return $this
->config
->io()
->files()
->temporary(Sequence::of())
->flatMap(
static fn($tmp) => $chunks
->sink($tmp->push()->chunk(...))
->attempt(
static fn($push, $chunk) => $chunk
->attempt(static fn() => new \RuntimeException('Failed to load chunk'))
->unwrap(),
),
)
->memoize() // to make sure writing the chunks has been done
->map(static fn($tmp) => $tmp->read())
->map(Content::io(...))
->unwrap(),
);
->flatMap($push)
->map(static fn() => $push),
)
->map(static fn() => $tmp->read()),
)
->map(Content::io(...));
}
}