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

viaf-import.js 1.0 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
  1. const zlib = require('zlib');
  2. const fs = require('fs-extra');
  3. const pg = require('pg');
  4. const io = require('./io');
  5. const pgutil = require('./pgutil');
  6. const marc = require('./parse-marc');
  7. async function importVIAF(file) {
  8. const client = new pg.Client();
  9. await client.connect();
  10. let stream = pgutil.openCopyStream('viaf_marc_field');
  11. let input = io.externalDecompress(file);
  12. let promise = new Promise((ok, fail) => {
  13. stream.on('error', fail);
  14. stream.on('end', ok);
  15. input.on('error', fail);
  16. })
  17. input.pipe(marc.parseVIAFLines())
  18. .pipe(marc.renderPostgresText())
  19. .pipe(stream);
  20. try {
  21. await promise;
  22. } finally {
  23. await client.end();
  24. }
  25. }
  26. module.exports.import = importVIAF;
  27. function convertVIAF(infile, outfile) {
  28. return io.openFile(infile)
  29. .pipe(zlib.createUnzip())
  30. .pipe(marc.parseVIAFLines())
  31. .pipe(marc.renderPostgresText())
  32. .pipe(zlib.createGzip())
  33. .pipe(fs.createWriteStream(outfile));
  34. }
  35. module.exports.convert = convertVIAF;
Tip!

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

Comments

Loading...