Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

test-scan.js 1.2 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
  1. "use strict";
  2. const zlib = require('zlib');
  3. const fs = require('fs');
  4. const through = require('through2');
  5. const fws = require('flush-write-stream');
  6. const io = require('./lib/io.js');
  7. const options = require('yargs').argv;
  8. const infn = options._[0];
  9. const throughput = {
  10. start: process.hrtime(),
  11. nrecs: 0,
  12. tsize: 0,
  13. advance: function(n) {
  14. this.nrecs += 1;
  15. this.tsize += n;
  16. if (this.nrecs % 10000 == 0) {
  17. this.print();
  18. }
  19. },
  20. print: function() {
  21. var now = process.hrtime(this.start);
  22. var ftime = now[0] + now[1] * 1.0e-9;
  23. console.info("processed %d records in %ss (%srecs/s; average length %s)",
  24. this.nrecs, ftime.toFixed(3), (this.nrecs / ftime).toFixed(0),
  25. (this.tsize / this.nrecs).toFixed(0));
  26. }
  27. };
  28. io.openFile(infn, (err, stream) => {
  29. if (err) throw err;
  30. stream.pipe(zlib.createUnzip())
  31. .pipe(io.decodeLines())
  32. .pipe(fws.obj((rec, enc, cb) => {
  33. throughput.advance(Object.keys(rec).length);
  34. cb();
  35. }), (cb) => {
  36. throughput.print();
  37. console.info("finished");
  38. cb();
  39. });
  40. })
  41. fs.createReadStream(infn)
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...