Skip to content

Commit

Permalink
Improve stream open mode
Browse files Browse the repository at this point in the history
  • Loading branch information
nyamsprod committed Nov 14, 2024
1 parent 0269772 commit 1138036
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/JsonConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}

/**
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 1138036

Please sign in to comment.