Skip to content

Commit 12c9a7b

Browse files
committed
Merge branch 'master' of github.com:soarecostin/file-vault
2 parents db0cf6d + f8b82ef commit 12c9a7b

File tree

1 file changed

+32
-10
lines changed

1 file changed

+32
-10
lines changed

README.md

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,33 +24,55 @@ composer require soarecostin/file-vault
2424

2525
This package will automatically register a facade called `FileVault`.
2626

27-
#### Encrypting a file
27+
### Encrypting a file
2828

2929
The `encrypt` method will search for a file, encrypt it and save it in the same directory.
3030

3131
``` php
3232
public function encrypt(string $sourceFile, string $destFile = null, $deleteSource = true)
3333
```
3434

35-
Examples:
35+
#### Examples:
3636

37+
The following example will search for `file.txt` into the `local` disk, save the encrypted file as `file.txt.enc` and delete the original `file.txt`:
3738
``` php
38-
// The following example will search for file.txt into the local disk,
39-
// save the encrypted file as file.txt.enc and delete the original file.txt
4039
FileVault::encrypt("file.txt");
40+
```
41+
42+
You can also specify a different `disk`, just as you would normally with the Laravel `Storage` facade:
43+
``` php
44+
FileVault::disk('s3')->encrypt("file.txt");
45+
```
4146

42-
// The following example will search for file.txt into the local disk,
43-
// save the encrypted file as encrypted.txt and delete the original file.txt
47+
The following example will search for `file.txt` into the `local` disk, save the encrypted file as `encrypted.txt` and delete the original `file.txt`:
48+
``` php
4449
FileVault::encrypt("file.txt", "encrypted.txt");
50+
```
4551

46-
// The following examples all achive the same thing as above,
47-
// with the difference that the original file is preserved
48-
FileVault::encrypt("file.txt", null, false);
49-
FileVault::encrypt("file.txt", "encrypted.txt", false);
52+
The following examples both achive the same results as above, with the only difference that the original file is not deleted:
53+
``` php
54+
// save the encrypted copy to file.txt.enc
5055
FileVault::encryptCopy("file.txt");
56+
57+
// or save the encrypted copy with a different name
5158
FileVault::encryptCopy("file.txt", "encrypted.txt");
5259
```
5360

61+
### Decrypting a file
62+
63+
The `decrypt` method will search for a file, decrypt it and save it in the same directory
64+
65+
66+
### Streaming a decrypted file
67+
68+
Sometimes you will only want to allow users to download the decrypted file, but you don't need to store the actual decrypted file. For this, you can use the `streamDecrypt` function that will decrypt the file and will write it to the `php://output` stream. You can use the Laravel [`streamDownload` method](https://laravel.com/docs/6.x/responses#file-downloads) (available since 5.6) in order to generate a downloadable response:
69+
70+
``` php
71+
return response()->streamDownload(function () {
72+
FileVault::streamDecrypt('file.txt')
73+
}, 'laravel-readme.md');
74+
```
75+
5476
## Testing
5577

5678
Run the tests with:

0 commit comments

Comments
 (0)