You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 14, 2025. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+66-52Lines changed: 66 additions & 52 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -39,14 +39,69 @@ Use [Composer](https://getcomposer.org) to install this library (note the [Requi
39
39
composer require awesomized/crc-fast
40
40
```
41
41
42
+
## Configuration
43
+
[FFI ini](https://www.php.net/manual/en/ffi.configuration.php) settings must be configured properly for your environment.
44
+
45
+
Optionally, opcache [preloading](https://www.php.net/manual/en/ffi.examples-complete.php) can also be used as an optimization.
42
46
43
47
## Usage
44
48
45
49
Examples are for `CRC-64/NVME`, but `CRC-32/ISO-HDLC` is nearly identical, just in a different namespace (`Awesomized\Checksums\Crc32\IsoHdlc`).
46
50
47
-
### Creating the CRC-64/NVME FFI object
51
+
Make sure you have the correct header file(s) for your CPU architecture and OS in [/include](include) for your project (e.g., [include/crc64nvme-aarch64-linux.h](include/crc64nvme-aarch64-linux.h)) which points to the correct shared library for your environment.
52
+
53
+
### Calculate CRC-64/NVME checksums:
54
+
55
+
```php
56
+
use Awesomized\Checksums\Crc64\Nvme;
57
+
58
+
// calculate the checksum of a string
59
+
$checksum = Nvme\Computer::calculate(
60
+
string: 'hello, world!'
61
+
// optionally inject a different FFI here
62
+
); // f8046e40c403f1d0
63
+
64
+
// calculate the checksum of a file, which will chunk through the file optimally,
65
+
// limiting RAM usage and maximizing throughput
66
+
$checksum = Nvme\Computer::calculateFile(
67
+
filename: 'path/to/hello-world'
68
+
// optionally inject a different FFI here
69
+
); // f8046e40c403f1d0
70
+
```
71
+
72
+
### Calculate CRC-64/NVME checksums with a Digest for intermittent / streaming / etc workloads:
73
+
74
+
```php
75
+
use Awesomized\Checksums\Crc64\Nvme;
48
76
49
-
A [helper FFI Class](src/Ffi.php) is provided, which supplies many ways to easily create an FFI object for the [crc64fast-nvme](https://github.com/awesomized/crc64fast-nvme) shared library:
Alternatively, you can create an FFI object directly, and inject it into the `Computer` classes:
94
+
95
+
#### - Via automagic loading via preloading and/or header files (recommended for most use cases):
96
+
97
+
```php
98
+
use Awesomized\Checksums\Crc64\Nvme;
99
+
100
+
// uses the opcache preloaded shared library, if possible, otherwise uses the header file
101
+
$crc64Fast = Nvme\Ffi::fromAuto();
102
+
```
103
+
104
+
Alternatively, a [helper FFI Class](src/Ffi.php) is provided, which supplies many ways to easily create an FFI object for the [crc64fast-nvme](https://github.com/awesomized/crc64fast-nvme) shared library:
50
105
51
106
#### - Via [preloaded](https://www.php.net/manual/en/ffi.examples-complete.php) shared library (recommended for any long-running workloads, such as web requests):
52
107
@@ -67,7 +122,7 @@ use Awesomized\Checksums\Crc64\Nvme;
67
122
68
123
// uses the FFI_LIB and FFI_SCOPE definitions in the header file
69
124
$crc64Fast = Nvme\Ffi::fromHeaderFile(
70
-
headerFile: 'path/to/crc64fast_nvme.h', // optional, can likely be inferred from the OS
125
+
headerFile: 'path/to/crc64nvme-ARCH-OS.h', // optional, can likely be inferred from the OS
0 commit comments