From c814c1262eb552b8127dcb927841f799a21dba81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joan=20Fabr=C3=A9gat?= Date: Fri, 23 Feb 2024 17:28:42 -0800 Subject: [PATCH] fix --- src/Exception.php | 1 + src/Pdf2TxtClient.php | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Exception.php b/src/Exception.php index 0ba259e..c95a5a0 100644 --- a/src/Exception.php +++ b/src/Exception.php @@ -16,6 +16,7 @@ class Exception extends BaseException { public const int ERROR_FILE_OPEN = 100; + public const int ERROR_FILE_WRITE = 110; public const int ERROR_REQUEST = 200; public const int ERROR_RESPONSE = 300; } \ No newline at end of file diff --git a/src/Pdf2TxtClient.php b/src/Pdf2TxtClient.php index 4edeafc..33ce1df 100644 --- a/src/Pdf2TxtClient.php +++ b/src/Pdf2TxtClient.php @@ -154,7 +154,10 @@ public function saveStreamToFile(StreamInterface $stream, string $path, string $ throw new Exception("The file '$path' could not be opened", Exception::ERROR_FILE_OPEN); } - stream_copy_to_stream($stream->detach(), $f); + if (stream_copy_to_stream($stream->detach(), $f) === false) { + throw new Exception("The stream could not be copied to the file '$path'", Exception::ERROR_FILE_WRITE); + } + fclose($f); }