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.1 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
  1. const zlib = require('zlib');
  2. const fs = require('fs-extra');
  3. const pg = require('pg');
  4. const copyFrom = require('pg-copy-streams').from;
  5. const io = require('./io');
  6. const marc = require('./parse-marc');
  7. async function importVIAF(file) {
  8. const client = new pg.Client();
  9. await client.connect();
  10. let stream = client.query(copyFrom('COPY viaf_marc_field FROM STDIN'));
  11. let input = io.openFile(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(zlib.createUnzip())
  18. .pipe(marc.parseVIAFLines())
  19. .pipe(marc.renderPostgresText())
  20. .pipe(stream);
  21. try {
  22. await promise;
  23. } finally {
  24. await client.end();
  25. }
  26. }
  27. module.exports.import = importVIAF;
  28. function convertVIAF(infile, outfile) {
  29. return io.openFile(infile)
  30. .pipe(zlib.createUnzip())
  31. .pipe(marc.parseVIAFLines())
  32. .pipe(marc.renderPostgresText())
  33. .pipe(zlib.createGzip())
  34. .pipe(fs.createWriteStream(outfile));
  35. }
  36. module.exports.convert = convertVIAF;
Tip!

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

Comments

Loading...