Skip to content

Commit 18967dc

Browse files
committed
use push strategy to create temporary file to avoid throwing exceptions
1 parent adbf567 commit 18967dc

1 file changed

Lines changed: 16 additions & 16 deletions

File tree

src/Filesystem/Generic.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -115,22 +115,22 @@ public function watch(Path $path): Ping
115115
#[\Override]
116116
public function temporary(Sequence $chunks): Attempt
117117
{
118-
return Attempt::of(
119-
fn() => $this
120-
->config
121-
->io()
122-
->files()
123-
->temporary(
124-
$chunks->map(
125-
static fn($chunk) => $chunk
118+
return $this
119+
->config
120+
->io()
121+
->files()
122+
->temporary(Sequence::of())
123+
->flatMap(
124+
static fn($tmp) => $chunks
125+
->sink($tmp->push()->chunk(...))
126+
->attempt(
127+
static fn($push, $chunk) => $chunk
126128
->attempt(static fn() => new \RuntimeException('Failed to load chunk'))
127-
->unwrap(),
128-
),
129-
)
130-
->memoize() // to make sure writing the chunks has been done
131-
->map(static fn($tmp) => $tmp->read())
132-
->map(Content::io(...))
133-
->unwrap(),
134-
);
129+
->flatMap($push)
130+
->map(static fn() => $push),
131+
)
132+
->map(static fn() => $tmp->read()),
133+
)
134+
->map(Content::io(...));
135135
}
136136
}

0 commit comments

Comments
 (0)