build-reject-domainset-worker.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // @ts-check
  2. const Piscina = require('piscina');
  3. const Trie = require('../lib/trie');
  4. // const { isCI } = require('ci-info');
  5. /** @type {string[]} */
  6. const fullsetDomainStartsWithADot = Piscina.workerData;
  7. const totalLen = fullsetDomainStartsWithADot.length;
  8. const DOT = '.';
  9. // const log = isCI ? () => { } : console.log.bind(console);
  10. /**
  11. * @param {{ chunk: string[] }} param0
  12. */
  13. module.exports = ({ chunk }) => {
  14. const chunkLength = chunk.length;
  15. const outputToBeRemoved = new Int8Array(chunkLength);
  16. const trie = Trie.from(chunk);
  17. for (let j = 0; j < totalLen; j++) {
  18. const domainStartsWithADotAndFromFullSet = fullsetDomainStartsWithADot[j];
  19. const found = trie.find(domainStartsWithADotAndFromFullSet, false)
  20. if (found.length) {
  21. found.forEach(f => {
  22. const index = chunk.indexOf(f);
  23. if (index !== -1) {
  24. outputToBeRemoved[index] = 1;
  25. }
  26. })
  27. }
  28. const a = domainStartsWithADotAndFromFullSet.slice(1);
  29. if (trie.has(a)) {
  30. const index = chunk.indexOf(a);
  31. if (index !== -1) {
  32. outputToBeRemoved[index] = 1;
  33. }
  34. }
  35. }
  36. return Piscina.move(outputToBeRemoved);
  37. };