*refactor continued

This commit is contained in:
Derrick Hammer 2023-04-17 02:39:48 -04:00
parent 9f0daf8952
commit d0646ac7c4
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 0 additions and 34 deletions

View File

@ -179,21 +179,6 @@ export default class IpfsProvider extends BaseProvider {
// @ts-ignore
for await (const chunk of reader.iterable()) {
streamWriter.write(chunk);
if (bufferRead < fileTypeBufferLength) {
if (chunk.length >= fileTypeBufferLength) {
mimeBuffer.push(chunk.slice(0, fileTypeBufferLength));
bufferRead += fileTypeBufferLength;
} else {
mimeBuffer.push(chunk);
bufferRead += chunk.length;
}
if (bufferRead >= fileTypeBufferLength) {
checkMime = true;
}
} else {
checkMime = true;
}
}
} catch (e) {
streamWriter.releaseLock();
@ -201,25 +186,6 @@ export default class IpfsProvider extends BaseProvider {
return;
}
if (checkMime) {
const mime = await fileTypeFromBuffer(
mimeBuffer.reduce((acc, val) => {
return new Uint8Array([...acc, ...val]);
}, new Uint8Array())
);
if (mime) {
provider.setData(details, "contentType", mime.mime);
}
if (!mime) {
const ext = path.parse(urlPath).ext.replace(".", "");
if (extToMimes.has(ext)) {
provider.setData(details, "contentType", extToMimes.get(ext));
}
}
}
streamWriter.releaseLock();
reqStream.close();
})();