src/manager.js
async function checkTorrentIntegrity(torrentFile, dataFile) {
	const _ntRead = promisify(nt.read);
	return _ntRead(torrentFile)
    .then((torrent) => {
      return new Promise((resolve, reject) => {
        torrent.metadata.info.name = path.basename(dataFile);
        const hasher = torrent.hashCheck(path.dirname(dataFile));

        let percentMatch = 0;
        const errors = [];

        hasher.on('match', (i, hash, percent) => {
          percentMatch = percent;
        });

        hasher.on('error', (err) => {
          errors.push(err.message);
        });

        hasher.on('end', () => {
          if(errors.length > 0) {
            reject(errors);
          } else {
            resolve({
              'success': percentMatch === 100,
              'hash': torrent.infoHash()
            });
          }
        });
      });
    });
}
async function checkTorrentIntegrity(torrentFile, dataFile) {
	const _ntRead = promisify(nt.read);
	return _ntRead(torrentFile)
    .then((torrent) => {
      return new Promise((resolve, reject) => {
        torrent.metadata.info.name = path.basename(dataFile);
        const hasher = torrent.hashCheck(path.dirname(dataFile));

        let percentMatch = 0;
        const errors = [];

        hasher.on('match', (i, hash, percent) => {
          percentMatch = percent;
        });

        hasher.on('error', (err) => {
          errors.push(err.message);
        });

        hasher.on('end', () => {
          if(errors.length > 0) {
            reject(errors);
          } else {
            resolve({
              'success': percentMatch === 100,
              'hash': torrent.infoHash()
            });
          }
        });
      });
    });
}
async function checkTorrentIntegrity ( torrentFile , dataFile ) { const _ntRead = promisify ( nt . read ) ; return _ntRead ( torrentFile ) . then ( ( torrent ) => { return new Promise ( ( resolve , reject ) => { torrent . metadata . info . name = path . basename ( dataFile ) ; const hasher = torrent . hashCheck ( path . dirname ( dataFile ) ) ; let percentMatch = 0 ; const errors = [ ] ; hasher . on ( 'match' , ( i , hash , percent ) => { percentMatch = percent ; } ) ; hasher . on ( 'error' , ( err ) => { errors . push ( err . message ) ; } ) ; hasher . on ( 'end' , ( ) => { if ( errors . length > 0 ) { reject ( errors ) ; } else { resolve ( { 'success' : percentMatch === 100 , 'hash' : torrent . infoHash ( ) } ) ; } } ) ; } ) ; } ) ; }
Check integrity between torrent and data
@param torrentFile
@param dataFile
@return {Promise.<TResult>|*}
Check integrity between torrent and data