From 113803644df7ebe15383167335bb28e7a4a77174 Mon Sep 17 00:00:00 2001 From: ignace nyamagana butera Date: Thu, 14 Nov 2024 22:58:25 +0100 Subject: [PATCH] Improve stream open mode --- src/JsonConverter.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/JsonConverter.php b/src/JsonConverter.php index b9030f0c..3f666230 100644 --- a/src/JsonConverter.php +++ b/src/JsonConverter.php @@ -365,7 +365,7 @@ public function download(iterable $records, ?string $filename = null): int HttpHeaders::forFileDownload($filename, 'application/json; charset=utf-8'); } - return $this->save($records, new SplFileObject('php://output', 'w')); + return $this->save($records, new SplFileObject('php://output', 'wb')); } /** @@ -408,9 +408,9 @@ public function save(iterable $records, mixed $destination, $context = null): in $stream = match (true) { $destination instanceof Stream, $destination instanceof SplFileObject => $destination, - $destination instanceof SplFileInfo => $destination->openFile(mode:'w', context: $context), + $destination instanceof SplFileInfo => $destination->openFile(mode:'wb', context: $context), is_resource($destination) => Stream::createFromResource($destination), - is_string($destination) => Stream::createFromPath($destination, 'w', $context), + is_string($destination) => Stream::createFromPath($destination, 'wb', $context), default => throw new TypeError('The destination path must be a filename, a stream or a SplFileInfo object.'), }; $bytes = 0;