Skip to content

Commit d1b8ec8

Browse files
committed
fix: update fs documentation mismatch
1 parent 6c9189f commit d1b8ec8

File tree

1 file changed

+81
-30
lines changed

1 file changed

+81
-30
lines changed

src/docs/utils/fs.md

Lines changed: 81 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,10 @@ if ($created) {
109109

110110
### Reading Files
111111

112-
Reading files means getting the content of a file. You can read files using the `readFile()` method. It takes in the file path and returns the file content.
112+
Reading files means getting the content of a file. You can read files using the `read()` method. It takes in the file path and returns the file content.
113113

114114
```php
115-
$content = storage()->readFile('path/to/file.txt');
115+
$content = storage()->read('path/to/file.txt');
116116

117117
echo $content;
118118
```
@@ -148,10 +148,10 @@ $info = storage()->fileInfo('path/to/file.txt');
148148
Or by using more specific methods:
149149

150150
```php
151-
$size = storage()->fileSize('path/to/file.txt'); // in bytes
152-
$type = storage()->fileType('path/to/file.txt'); // file type
153-
$lastModified = storage()->fileLastModified('path/to/file.txt'); // last modified time
154-
$extension = storage()->extname('path/to/file.txt'); // txt
151+
$size = storage()->size('path/to/file.txt'); // in bytes
152+
$type = storage()->type('path/to/file.txt'); // file type
153+
$lastModified = storage()->lastModified('path/to/file.txt'); // last modified time
154+
$extension = storage()->extension('path/to/file.txt'); // txt
155155
$basename = storage()->basename('path/to/file.txt'); // file.txt
156156
$dirname = storage()->dirname('path/to/file.txt'); // path/to
157157
```
@@ -189,27 +189,27 @@ $uploaded = storage()->upload('fileToUpload', 'path/to/uploads', [
189189

190190
This is a list of config options for the `upload()` method:
191191

192-
| Config Name | Description | Possible Values |
193-
| :----------- | :----------------------------------------------------------- | ------------------------------------------------------------------------------------: |
194-
| mode | Permissions to create your destination folder if it doesn't exist | Any permissions accepted by mkdir() |
195-
| overwrite | If `true`, Leaf will overwrite the file if it already exists | `true`, `false` |
196-
| rename | If `true`, Leaf will rename the file if it already exists | `true`, `false` |
197-
| validate | If `true`, Leaf will validate the file before uploading | `true`, `false` |
198-
| maxSize | The maximum file size allowed in bytes | `int` |
199-
| allowedTypes | The allowed file types | `image`, `video`, `audio`, `presentation`, `compressed`, `spreadsheet`, `application`, `custom` |
192+
| Config Name | Description | Possible Values |
193+
| :----------- | :---------------------------------------------------------------- | ----------------------------------------------------------------------------------------------: |
194+
| mode | Permissions to create your destination folder if it doesn't exist | Any permissions accepted by mkdir() |
195+
| overwrite | If `true`, Leaf will overwrite the file if it already exists | `true`, `false` |
196+
| rename | If `true`, Leaf will rename the file if it already exists | `true`, `false` |
197+
| validate | If `true`, Leaf will validate the file before uploading | `true`, `false` |
198+
| maxSize | The maximum file size allowed in bytes | `int` |
199+
| allowedTypes | The allowed file types | `image`, `video`, `audio`, `presentation`, `compressed`, `spreadsheet`, `application`, `custom` |
200200

201201
This is a list of values Leaf uses to check for file types:
202202

203-
| File Type | Common Extensions |
204-
| :-------------- | :---------------------------------------------- |
205-
| image | 'jpg', 'jpeg', 'png', 'gif', 'webp', 'apng', 'tif', 'tiff', 'svg', 'pjpeg', 'pjp', 'jfif', 'cur', 'ico' |
206-
| video | 'mp4', 'webm', 'swf', 'flv' |
207-
| audio |'wav', 'mp3', 'ogg', 'm4a' |
208-
| text |'txt', 'log', 'xml', 'doc', 'docx', 'odt', 'wpd', 'rtf', 'tex', 'pdf' |
209-
| presentation |'ppsx', 'pptx', 'ppt', 'pps', 'ppsm', 'key', 'odp' |
210-
| compressed |'zip', 'rar', 'bz', 'gz', 'iso', 'tar.gz', 'tgz', 'zipx', '7z', 'dmg'|
211-
| spreadsheet |'ods', 'xls', 'xlsx', 'xlsm' |
212-
| application |'apk', 'bat', 'cgi', 'pl', 'com', 'exe', 'gadget', 'jar', 'msi', 'py', 'wsf' |
203+
| File Type | Common Extensions |
204+
| :----------- | :------------------------------------------------------------------------------------------------------ |
205+
| image | 'jpg', 'jpeg', 'png', 'gif', 'webp', 'apng', 'tif', 'tiff', 'svg', 'pjpeg', 'pjp', 'jfif', 'cur', 'ico' |
206+
| video | 'mp4', 'webm', 'swf', 'flv' |
207+
| audio | 'wav', 'mp3', 'ogg', 'm4a' |
208+
| text | 'txt', 'log', 'xml', 'doc', 'docx', 'odt', 'wpd', 'rtf', 'tex', 'pdf' |
209+
| presentation | 'ppsx', 'pptx', 'ppt', 'pps', 'ppsm', 'key', 'odp' |
210+
| compressed | 'zip', 'rar', 'bz', 'gz', 'iso', 'tar.gz', 'tgz', 'zipx', '7z', 'dmg' |
211+
| spreadsheet | 'ods', 'xls', 'xlsx', 'xlsm' |
212+
| application | 'apk', 'bat', 'cgi', 'pl', 'com', 'exe', 'gadget', 'jar', 'msi', 'py', 'wsf' |
213213

214214
## Working with Folders
215215

@@ -254,24 +254,53 @@ You can check if a folder is empty using the `isEmpty()` method. It takes in the
254254
$isEmpty = storage()->isEmpty('path/to/folder');
255255
```
256256

257-
You can also get the contents of a folder using the `listDir()` method. It takes in the folder path and a key to sort the contents by. It returns an array of the folder contents.
257+
You can also get the contents of a folder using the `list()` method. It takes in the folder path and a key to sort the contents by. It returns an array of the folder contents.
258258

259259
```php
260-
$contents = storage()->listDir('path/to/folder');
261-
$phpFiles = storage()->listDir('path/to/folder', '*.php');
260+
$contents = storage()->list('path/to/folder');
261+
$phpFiles = storage()->list('path/to/folder', '*.php');
262262
```
263263

264-
If you need to do more complex filtering, you can pass a function as the second parameter to the `listDir()` method.
264+
If you need to do more complex filtering, you can pass a function as the second parameter to the `list()` method.
265265

266266
```php
267-
$contents = storage()->listDir('path/to/folder', function ($file) {
267+
$contents = storage()->list('path/to/folder', function ($file) {
268268
// if true, the file will be included in the results
269-
return $file->isFile() && $file->extname() === 'php';
269+
return storage()->isFile($file) && storage()->extension($file) === 'php';
270270
});
271271
```
272272

273273
<!-- ## Working with Cloud Storage -->
274274

275+
### File/Folder permissions
276+
277+
You can set file/folder permissions using the `chmod()` method. It takes in the file/folder path and the permissions to set.
278+
279+
```php
280+
storage()->chmod('path/to/file.txt', 0777);
281+
```
282+
283+
If you are not sure of the current permissions of a file/folder, you can get them using the same method.
284+
285+
```php
286+
$permissions = storage()->chmod('path/to/file.txt');
287+
```
288+
289+
### Checking if a file exists
290+
291+
You can check if a file or folder exists using the `exists()` method. It takes in the file path and returns a boolean indicating whether the file exists.
292+
293+
```php
294+
$exists = storage()->exists('path/to/file.txt');
295+
```
296+
297+
This will return true if the path matches an existing folder or file, but if you want to get more specific, you can use the `isFile()` and `isFolder()` methods to check if a path is a file or folder.
298+
299+
```php
300+
$isFile = storage()->isFile('path/to/file.txt');
301+
$isFolder = storage()->isFolder('path/to/folder');
302+
```
303+
275304
## Renaming Files and Folders
276305

277306
There are instances where you might need to rename files or folders. Leaf provides a simple way to rename files and folders using the `rename()` method. It takes in 2 parameters:
@@ -361,6 +390,28 @@ if ($moved) {
361390
}
362391
```
363392

393+
## Symlinks/Shortcuts
394+
395+
Symlinks are shortcuts to files or folders. They allow you to access a file or folder from a different location. Leaf provides a simple way to create symlinks using the `symlink()` method. It takes in 2 parameters:
396+
397+
- the target file/folder path
398+
- the symlink path
399+
400+
```php
401+
storage()->link('path/to/file.txt', 'path/to/symlink.txt');
402+
storage()->link('path/to/folder', 'path/to/symlink');
403+
```
404+
405+
It returns a boolean indicating whether the symlink was created successfully.
406+
407+
```php
408+
$linked = storage()->link('path/to/file.txt', 'path/to/symlink.txt');
409+
410+
if ($linked) {
411+
echo 'Symlink created successfully';
412+
}
413+
```
414+
364415
<!-- ## Working with Streams
365416
366417
Streaming is a way to read and write data from a source or to a destination. Leaf provides a simple way to work with streams using the `stream()` function.

0 commit comments

Comments
 (0)