@iebh/reflib 2.5.5 → 2.5.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.ignore +1 -1
- package/LICENSE +20 -20
- package/README.md +271 -271
- package/lib/browser.js +30 -30
- package/lib/default.js +30 -30
- package/lib/downloadFile.js +94 -94
- package/lib/fields.js +158 -158
- package/lib/formats.js +77 -77
- package/lib/getModule.js +39 -39
- package/lib/getRefDoi.js +16 -16
- package/lib/identifyFormat.js +13 -13
- package/lib/readFile.js +63 -63
- package/lib/readStream.js +21 -21
- package/lib/uploadFile.js +71 -71
- package/lib/writeFile.js +31 -31
- package/lib/writeStream.js +16 -16
- package/modules/default.js +6 -6
- package/modules/endnoteEnl.js +237 -237
- package/modules/endnoteEnlX.js +85 -85
- package/modules/endnoteXml.js +435 -435
- package/modules/interface.js +46 -46
- package/modules/json.js +79 -79
- package/modules/medline.js +638 -638
- package/modules/ris.js +366 -366
- package/modules/shims/JSONStream-browser.js +43 -43
- package/modules/shims/WritableStream-browser.js +51 -51
- package/package.json +65 -65
- package/shared/camelCase.js +17 -17
- package/shared/emitter.js +23 -23
- package/shared/streamEmitter.js +61 -61
package/modules/endnoteEnlX.js
CHANGED
|
@@ -1,85 +1,85 @@
|
|
|
1
|
-
import * as EndNoteEnl from './endnoteEnl.js';
|
|
2
|
-
import Emitter from '../shared/emitter.js';
|
|
3
|
-
import {BlobReader as ZipBlobReader, ZipReader, Writer} from '@zip.js/zip.js';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Utility class to read a Zip file into a Uint8Array
|
|
7
|
-
* This extends the deafult @zip.js/zip.js Writer class so its works without a crowbar
|
|
8
|
-
*/
|
|
9
|
-
class BinaryStringWriter extends Writer {
|
|
10
|
-
chunks = [];
|
|
11
|
-
|
|
12
|
-
writeUint8Array(chunk) {
|
|
13
|
-
this.chunks.push(chunk);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
getData() {
|
|
17
|
-
let buf = new Uint8Array(
|
|
18
|
-
this.chunks.reduce((total, chunk) => total + chunk.length, 0)
|
|
19
|
-
);
|
|
20
|
-
|
|
21
|
-
let position = 0;
|
|
22
|
-
this.chunks.forEach(chunk => {
|
|
23
|
-
buf.set(chunk, position);
|
|
24
|
-
position += chunk.length;
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
// Flush buffer to free up memory
|
|
28
|
-
this.chunks = [];
|
|
29
|
-
|
|
30
|
-
return buf;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Read an EndNote(@11+) / Zip+SQLite database EnlX returning an Emitter analogue
|
|
37
|
-
*
|
|
38
|
-
* Since EnlX files are really just a Zip file containing the SQLite database we're actually intrestesd in, most of this module
|
|
39
|
-
* is handling the Zip container and handing the extracted buffer to the regular modules/endnoteEnl.js driver
|
|
40
|
-
*
|
|
41
|
-
* @see modules/inhterface.js
|
|
42
|
-
*
|
|
43
|
-
* @param {Stream} stream Stream primative to encapsulate
|
|
44
|
-
*
|
|
45
|
-
* @returns {Object} An Emitter analogue defined in `../shared/Emitter.js`
|
|
46
|
-
*/
|
|
47
|
-
export function readStream(stream) {
|
|
48
|
-
let emitter = Emitter();
|
|
49
|
-
|
|
50
|
-
// Queue up the parser in the next tick (so we can return the emitter first)
|
|
51
|
-
setTimeout(()=> {
|
|
52
|
-
let chunks = []; // Gathered buffer chunks, used to make an arrayBuffer later
|
|
53
|
-
|
|
54
|
-
stream
|
|
55
|
-
.on('data', chunk => chunks.push(chunk))
|
|
56
|
-
.on('error', e => emitter.emit('error', e))
|
|
57
|
-
.on('end', ()=> {
|
|
58
|
-
Promise.resolve()
|
|
59
|
-
.then(()=> { // Parse chunks into a Blob
|
|
60
|
-
let blob = new Blob(chunks);
|
|
61
|
-
|
|
62
|
-
// Release chunks to free up memory
|
|
63
|
-
chunks = [];
|
|
64
|
-
return blob;
|
|
65
|
-
})
|
|
66
|
-
.then(blob => new ZipReader( // Create zipReader
|
|
67
|
-
new ZipBlobReader(blob),
|
|
68
|
-
))
|
|
69
|
-
.then(zip => zip.getEntries()) // Fetch files
|
|
70
|
-
.then(files => files.find(f => f.filename == 'sdb/sdb.eni')) // Find the file we want
|
|
71
|
-
.then(sdb => { // Extract that files stream
|
|
72
|
-
let writer = new BinaryStringWriter();
|
|
73
|
-
return sdb.getData(writer);
|
|
74
|
-
})
|
|
75
|
-
.then(buf => EndNoteEnl.readBuffer(buf, {
|
|
76
|
-
onRef(ref) {
|
|
77
|
-
emitter.emit('ref', ref);
|
|
78
|
-
},
|
|
79
|
-
}))
|
|
80
|
-
.finally(()=> emitter.emit('end'))
|
|
81
|
-
})
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
return emitter;
|
|
85
|
-
}
|
|
1
|
+
import * as EndNoteEnl from './endnoteEnl.js';
|
|
2
|
+
import Emitter from '../shared/emitter.js';
|
|
3
|
+
import {BlobReader as ZipBlobReader, ZipReader, Writer} from '@zip.js/zip.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Utility class to read a Zip file into a Uint8Array
|
|
7
|
+
* This extends the deafult @zip.js/zip.js Writer class so its works without a crowbar
|
|
8
|
+
*/
|
|
9
|
+
class BinaryStringWriter extends Writer {
|
|
10
|
+
chunks = [];
|
|
11
|
+
|
|
12
|
+
writeUint8Array(chunk) {
|
|
13
|
+
this.chunks.push(chunk);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
getData() {
|
|
17
|
+
let buf = new Uint8Array(
|
|
18
|
+
this.chunks.reduce((total, chunk) => total + chunk.length, 0)
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
let position = 0;
|
|
22
|
+
this.chunks.forEach(chunk => {
|
|
23
|
+
buf.set(chunk, position);
|
|
24
|
+
position += chunk.length;
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
// Flush buffer to free up memory
|
|
28
|
+
this.chunks = [];
|
|
29
|
+
|
|
30
|
+
return buf;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Read an EndNote(@11+) / Zip+SQLite database EnlX returning an Emitter analogue
|
|
37
|
+
*
|
|
38
|
+
* Since EnlX files are really just a Zip file containing the SQLite database we're actually intrestesd in, most of this module
|
|
39
|
+
* is handling the Zip container and handing the extracted buffer to the regular modules/endnoteEnl.js driver
|
|
40
|
+
*
|
|
41
|
+
* @see modules/inhterface.js
|
|
42
|
+
*
|
|
43
|
+
* @param {Stream} stream Stream primative to encapsulate
|
|
44
|
+
*
|
|
45
|
+
* @returns {Object} An Emitter analogue defined in `../shared/Emitter.js`
|
|
46
|
+
*/
|
|
47
|
+
export function readStream(stream) {
|
|
48
|
+
let emitter = Emitter();
|
|
49
|
+
|
|
50
|
+
// Queue up the parser in the next tick (so we can return the emitter first)
|
|
51
|
+
setTimeout(()=> {
|
|
52
|
+
let chunks = []; // Gathered buffer chunks, used to make an arrayBuffer later
|
|
53
|
+
|
|
54
|
+
stream
|
|
55
|
+
.on('data', chunk => chunks.push(chunk))
|
|
56
|
+
.on('error', e => emitter.emit('error', e))
|
|
57
|
+
.on('end', ()=> {
|
|
58
|
+
Promise.resolve()
|
|
59
|
+
.then(()=> { // Parse chunks into a Blob
|
|
60
|
+
let blob = new Blob(chunks);
|
|
61
|
+
|
|
62
|
+
// Release chunks to free up memory
|
|
63
|
+
chunks = [];
|
|
64
|
+
return blob;
|
|
65
|
+
})
|
|
66
|
+
.then(blob => new ZipReader( // Create zipReader
|
|
67
|
+
new ZipBlobReader(blob),
|
|
68
|
+
))
|
|
69
|
+
.then(zip => zip.getEntries()) // Fetch files
|
|
70
|
+
.then(files => files.find(f => f.filename == 'sdb/sdb.eni')) // Find the file we want
|
|
71
|
+
.then(sdb => { // Extract that files stream
|
|
72
|
+
let writer = new BinaryStringWriter();
|
|
73
|
+
return sdb.getData(writer);
|
|
74
|
+
})
|
|
75
|
+
.then(buf => EndNoteEnl.readBuffer(buf, {
|
|
76
|
+
onRef(ref) {
|
|
77
|
+
emitter.emit('ref', ref);
|
|
78
|
+
},
|
|
79
|
+
}))
|
|
80
|
+
.finally(()=> emitter.emit('end'))
|
|
81
|
+
})
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
return emitter;
|
|
85
|
+
}
|