-
-
Notifications
You must be signed in to change notification settings - Fork 98
Description
Don't do any special handling for ppl using node:Buffer treat it as any normal uint8array instead, so that ppl can pass in Uint8Array instead.
I suggest that you change the following code:
Lines 179 to 183 in 27d92fa
| if (isNodeBuffer(data)) { | |
| // File data read in Node can share the underlying buffer with other | |
| // data. Therefore it's safest to get a new one to avoid weird bugs. | |
| data = (new Uint8Array(data)).buffer; | |
| } |
to instead do this:
if (ArrayBuffer.isView(data)) {
data = new Uint8Array(data.buffer, data.byteOffset, data.byteLength).slice().buffer
}i think any appearance of the keyword Buffer should be omited, why? cdn delivery networks have a hard time figuring out if node:Buffer should be be bundled into the code and therefore include it anyway just to be safe,
look for instance in: https://cdn.jsdelivr.net/npm/exifreader@4.31.1/dist/exif-reader.js/+esm and search for allocUnsafe and you will notice that there is a node:buffer polyfill being imported into your project even if this can work without NodeJS specific features.
just by doing typeof Buffer === undefined means that cdn will include it (b/c it implies that you try to access globalThis.Buffer)
related: