mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-08-31 15:19:42 +02:00
Remove archiver dependency
This commit is contained in:
parent
415e0a7b5a
commit
ab08d83c04
35 changed files with 4046 additions and 194 deletions
48
server/libs/archiver/crc32-stream/crc32-stream.js
Normal file
48
server/libs/archiver/crc32-stream/crc32-stream.js
Normal file
|
@ -0,0 +1,48 @@
|
|||
/**
|
||||
* node-crc32-stream
|
||||
*
|
||||
* Copyright (c) 2014 Chris Talkington, contributors.
|
||||
* Licensed under the MIT license.
|
||||
* https://github.com/archiverjs/node-crc32-stream/blob/master/LICENSE-MIT
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const { Transform } = require('readable-stream');
|
||||
|
||||
const crc32 = require('../crc32');
|
||||
|
||||
class CRC32Stream extends Transform {
|
||||
constructor(options) {
|
||||
super(options);
|
||||
this.checksum = Buffer.allocUnsafe(4);
|
||||
this.checksum.writeInt32BE(0, 0);
|
||||
|
||||
this.rawSize = 0;
|
||||
}
|
||||
|
||||
_transform(chunk, encoding, callback) {
|
||||
if (chunk) {
|
||||
this.checksum = crc32.buf(chunk, this.checksum) >>> 0;
|
||||
this.rawSize += chunk.length;
|
||||
}
|
||||
|
||||
callback(null, chunk);
|
||||
}
|
||||
|
||||
digest(encoding) {
|
||||
const checksum = Buffer.allocUnsafe(4);
|
||||
checksum.writeUInt32BE(this.checksum >>> 0, 0);
|
||||
return encoding ? checksum.toString(encoding) : checksum;
|
||||
}
|
||||
|
||||
hex() {
|
||||
return this.digest('hex').toUpperCase();
|
||||
}
|
||||
|
||||
size() {
|
||||
return this.rawSize;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = CRC32Stream;
|
Loading…
Add table
Add a link
Reference in a new issue