Skip to content

Commit bf7285b

Browse files
committed
Add File::rewind()
In `File::guessIndentation()`, return the given `Indentation` instance if the default indentation appears to be used
1 parent 38a2ba1 commit bf7285b

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/Toolkit/Core/Utility/File.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,20 @@ public static function write($stream, string $data, ?int $length = null, $uri =
163163
return $result;
164164
}
165165

166+
/**
167+
* Rewind to the beginning of a stream
168+
*
169+
* Equivalent to `File::seek($stream, 0, \SEEK_SET, $uri)`.
170+
*
171+
* @param resource $stream
172+
* @param Stringable|string|null $uri
173+
* @throws FilesystemErrorException on failure.
174+
*/
175+
public static function rewind($stream, $uri = null): void
176+
{
177+
self::seek($stream, 0, \SEEK_SET, $uri);
178+
}
179+
166180
/**
167181
* Set the file position indicator for a stream
168182
*
@@ -433,6 +447,8 @@ public static function getEol($resource, $uri = null): ?string
433447
*
434448
* Derived from VS Code's `indentationGuesser`.
435449
*
450+
* Returns `$default` if `$resource` appears to use the default indentation.
451+
*
436452
* @param Stringable|string|resource $resource
437453
* @param Stringable|string|null $uri
438454
*
@@ -579,6 +595,14 @@ public static function guessIndentation(
579595
self::close($handle, $uri);
580596
}
581597

598+
if (
599+
$default &&
600+
$default->InsertSpaces === $insertSpaces &&
601+
$default->TabSize === $tabSize
602+
) {
603+
return $default;
604+
}
605+
582606
return new Indentation($insertSpaces, $tabSize);
583607
}
584608

0 commit comments

Comments
 (0)