Skip to content

Commit

Permalink
fix: Automatic detection of line endings (CR, CRLF, LF, etc.)
Browse files Browse the repository at this point in the history
  • Loading branch information
zak39 committed Dec 2, 2024
1 parent 5ccc15f commit 194de05
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/Files/FileUploader.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
class FileUploader implements FileInterface {
private $resource;

private string|false $lineEnding;

public function __construct(private string $path) {
}

Expand All @@ -13,6 +15,8 @@ public function __construct(private string $path) {
* @throws \Exception
*/
public function open(?string $path = null) {
$this->lineEnding = ini_get("auto_detect_line_endings");
ini_set("auto_detect_line_endings", true);
$this->resource = fopen($this->path, "r");

if (!$this->resource) {
Expand All @@ -23,6 +27,7 @@ public function open(?string $path = null) {
}

public function close(): bool {
ini_set("auto_detect_line_endings", $this->lineEnding);
return fclose($this->resource);
}

Expand Down
5 changes: 5 additions & 0 deletions lib/Files/NextcloudFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

class NextcloudFile implements FileInterface {
private $resource;

private string|false $lineEnding;

public function __construct(private Node $file) {
}
Expand All @@ -15,6 +17,8 @@ public function __construct(private Node $file) {
* @throws \Exception
*/
public function open(?string $path = null) {
$this->lineEnding = ini_get("auto_detect_line_endings");
ini_set("auto_detect_line_endings", true);
$store = $this->file->getStorage();
$this->resource = $store->fopen($this->file->getInternalPath(), "r");

Expand All @@ -26,6 +30,7 @@ public function open(?string $path = null) {
}

public function close(): bool {
ini_set("auto_detect_line_endings", $this->lineEnding);
return fclose($this->resource);
}

Expand Down

0 comments on commit 194de05

Please sign in to comment.