xml-twig 1.3.10 → 1.3.12
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/doc/twig.md +16 -0
- package/package.json +1 -1
- package/samples/memory-test.js +46 -41
- package/twig.js +7 -4
package/doc/twig.md
CHANGED
|
@@ -141,6 +141,7 @@ You can specify a <code>function</code> or a <code>event</code> name</p>
|
|
|
141
141
|
* [.pinned](#Twig+pinned) ⇒ <code>boolean</code>
|
|
142
142
|
* [.close](#Twig+close)
|
|
143
143
|
* [.debug](#Twig+debug) ⇒ <code>string</code>
|
|
144
|
+
* [.toString](#Twig+toString) ⇒ <code>string</code>
|
|
144
145
|
* [.addChild](#Twig+addChild) ℗
|
|
145
146
|
* [.writer](#Twig+writer) ⇒ [<code>XMLWriter</code>](https://www.npmjs.com/package/xml-writer)
|
|
146
147
|
* [.attr](#Twig+attr) ⇒ <code>string</code> \| <code>number</code> \| <code>object</code>
|
|
@@ -360,6 +361,13 @@ XML-Twig for dummies :-)
|
|
|
360
361
|
|
|
361
362
|
**Kind**: instance property of [<code>Twig</code>](#Twig)
|
|
362
363
|
**Returns**: <code>string</code> - The XML-Tree which is currently available in RAM - no valid XML Structure
|
|
364
|
+
<a name="Twig+toString"></a>
|
|
365
|
+
|
|
366
|
+
### twig.toString ⇒ <code>string</code>
|
|
367
|
+
Returns XML string of the element
|
|
368
|
+
|
|
369
|
+
**Kind**: instance property of [<code>Twig</code>](#Twig)
|
|
370
|
+
**Returns**: <code>string</code> - The XML-Element as string
|
|
363
371
|
<a name="Twig+addChild"></a>
|
|
364
372
|
|
|
365
373
|
### twig.addChild ℗
|
|
@@ -758,6 +766,7 @@ Common function to filter Twig element
|
|
|
758
766
|
* [.pinned](#Twig+pinned) ⇒ <code>boolean</code>
|
|
759
767
|
* [.close](#Twig+close)
|
|
760
768
|
* [.debug](#Twig+debug) ⇒ <code>string</code>
|
|
769
|
+
* [.toString](#Twig+toString) ⇒ <code>string</code>
|
|
761
770
|
* [.addChild](#Twig+addChild) ℗
|
|
762
771
|
* [.writer](#Twig+writer) ⇒ [<code>XMLWriter</code>](https://www.npmjs.com/package/xml-writer)
|
|
763
772
|
* [.attr](#Twig+attr) ⇒ <code>string</code> \| <code>number</code> \| <code>object</code>
|
|
@@ -977,6 +986,13 @@ XML-Twig for dummies :-)
|
|
|
977
986
|
|
|
978
987
|
**Kind**: instance property of [<code>Twig</code>](#Twig)
|
|
979
988
|
**Returns**: <code>string</code> - The XML-Tree which is currently available in RAM - no valid XML Structure
|
|
989
|
+
<a name="Twig+toString"></a>
|
|
990
|
+
|
|
991
|
+
### twig.toString ⇒ <code>string</code>
|
|
992
|
+
Returns XML string of the element
|
|
993
|
+
|
|
994
|
+
**Kind**: instance property of [<code>Twig</code>](#Twig)
|
|
995
|
+
**Returns**: <code>string</code> - The XML-Element as string
|
|
980
996
|
<a name="Twig+addChild"></a>
|
|
981
997
|
|
|
982
998
|
### twig.addChild ℗
|
package/package.json
CHANGED
package/samples/memory-test.js
CHANGED
|
@@ -2,26 +2,27 @@ const fs = require('fs');
|
|
|
2
2
|
const process = require('process');
|
|
3
3
|
const twig = require('xml-twig');
|
|
4
4
|
|
|
5
|
-
let
|
|
6
|
-
|
|
7
|
-
let parser = twig.createParser([{ tag: '
|
|
8
|
-
|
|
5
|
+
let Entry = 0;
|
|
6
|
+
|
|
7
|
+
let parser = twig.createParser([{ tag: 'Entry', function: EntryHandler }], { method: 'expat' })
|
|
8
|
+
// http://aiweb.cs.washington.edu/research/projects/xmltk/xmldata/data/SwissProt/SwissProt.xml.gz
|
|
9
|
+
// For more files see http://aiweb.cs.washington.edu/research/projects/xmltk/xmldata/www/repository.html
|
|
10
|
+
let reader = fs.createReadStream(`SwissProt.xml`);
|
|
9
11
|
reader.pipe(parser);
|
|
10
12
|
|
|
11
|
-
function
|
|
12
|
-
|
|
13
|
-
if (
|
|
13
|
+
function EntryHandler(elt) {
|
|
14
|
+
Entry++;
|
|
15
|
+
if (Entry % 10000 === 0) {
|
|
16
|
+
console.log(`Entry ${Entry}`)
|
|
17
|
+
let len = elt.root().writer().toString().length;
|
|
18
|
+
len = Math.round((len / 1024 / 1024 + Number.EPSILON) * 100) / 100;
|
|
19
|
+
console.log(`Size of XML string: ${len} MiB`);
|
|
14
20
|
for (const [key, value] of Object.entries(process.memoryUsage())) {
|
|
15
21
|
console.log(` Memory usage by ${key}, ${Math.round((value / 1024 / 1024 + Number.EPSILON) * 100) / 100} MiB`)
|
|
16
22
|
}
|
|
17
|
-
}
|
|
18
|
-
//elt.purge();
|
|
23
|
+
}
|
|
19
24
|
}
|
|
20
25
|
|
|
21
|
-
reader.on('end', () => {
|
|
22
|
-
console.log(`All done`);
|
|
23
|
-
});
|
|
24
|
-
|
|
25
26
|
|
|
26
27
|
|
|
27
28
|
/*
|
|
@@ -29,44 +30,48 @@ reader.on('end', () => {
|
|
|
29
30
|
* Results
|
|
30
31
|
**********************
|
|
31
32
|
|
|
33
|
+
# Set memory limit to 4GiB for demonstration reasons:
|
|
32
34
|
NODE_OPTIONS=--max-old-space-size=4096
|
|
33
35
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
Memory usage by
|
|
37
|
-
Memory usage by
|
|
38
|
-
Memory usage by
|
|
39
|
-
Memory usage by
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
Memory usage by
|
|
45
|
-
Memory usage by
|
|
36
|
+
Entry 10000
|
|
37
|
+
Size of XML string: 21.08 MiB
|
|
38
|
+
Memory usage by rss, 1897.36 MiB
|
|
39
|
+
Memory usage by heapTotal, 1855.68 MiB
|
|
40
|
+
Memory usage by heapUsed, 1807.43 MiB
|
|
41
|
+
Memory usage by external, 1.13 MiB
|
|
42
|
+
Memory usage by arrayBuffers, 0.7 MiB
|
|
43
|
+
|
|
44
|
+
Entry 20000
|
|
45
|
+
Size of XML string: 40.86 MiB
|
|
46
|
+
Memory usage by rss, 3615.75 MiB
|
|
47
|
+
Memory usage by heapTotal, 3562.62 MiB
|
|
48
|
+
Memory usage by heapUsed, 3482.97 MiB
|
|
49
|
+
Memory usage by external, 0.63 MiB
|
|
50
|
+
Memory usage by arrayBuffers, 0.2 MiB
|
|
46
51
|
|
|
47
52
|
<--- Last few GCs --->
|
|
48
53
|
|
|
49
|
-
[
|
|
50
|
-
[
|
|
54
|
+
[18648:000001F930FC8F90] 13906 ms: Scavenge 4047.7 (4123.2) -> 4047.3 (4133.7) MB, 3.4 / 0.0 ms (average mu = 0.332, current mu = 0.185) allocation failure;
|
|
55
|
+
[18648:000001F930FC8F90] 13916 ms: Scavenge 4054.1 (4133.7) -> 4053.8 (4135.2) MB, 4.0 / 0.0 ms (average mu = 0.332, current mu = 0.185) allocation failure;
|
|
56
|
+
[18648:000001F930FC8F90] 13925 ms: Scavenge 4055.1 (4135.2) -> 4054.3 (4156.2) MB, 8.3 / 0.0 ms (average mu = 0.332, current mu = 0.185) allocation failure;
|
|
51
57
|
|
|
52
58
|
|
|
53
59
|
<--- JS stacktrace --->
|
|
54
60
|
|
|
55
61
|
FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
|
|
56
|
-
1:
|
|
57
|
-
2:
|
|
58
|
-
3:
|
|
59
|
-
4:
|
|
60
|
-
5:
|
|
61
|
-
6:
|
|
62
|
-
7:
|
|
63
|
-
8:
|
|
64
|
-
9:
|
|
65
|
-
10:
|
|
66
|
-
11:
|
|
67
|
-
12:
|
|
68
|
-
13:
|
|
69
|
-
|
|
62
|
+
1: 00007FF604481C7F node_api_throw_syntax_error+175855
|
|
63
|
+
2: 00007FF604406476 EVP_MD_meth_get_input_blocksize+59654
|
|
64
|
+
3: 00007FF604408160 EVP_MD_meth_get_input_blocksize+67056
|
|
65
|
+
4: 00007FF604EB0434 v8::Isolate::ReportExternalAllocationLimitReached+116
|
|
66
|
+
5: 00007FF604E9B7C2 v8::Isolate::Exit+674
|
|
67
|
+
6: 00007FF604D1D65C v8::internal::EmbedderStackStateScope::ExplicitScopeForTesting+124
|
|
68
|
+
7: 00007FF604D1A87B v8::internal::Heap::CollectGarbage+3963
|
|
69
|
+
8: 00007FF604D30AB3 v8::internal::HeapAllocator::AllocateRawWithLightRetrySlowPath+2099
|
|
70
|
+
9: 00007FF604D3135D v8::internal::HeapAllocator::AllocateRawWithRetryOrFailSlowPath+93
|
|
71
|
+
10: 00007FF604D40B20 v8::internal::Factory::NewFillerObject+816
|
|
72
|
+
11: 00007FF604A31565 v8::internal::DateCache::Weekday+1349
|
|
73
|
+
12: 00007FF604F4D961 v8::internal::SetupIsolateDelegate::SetupHeap+558193
|
|
74
|
+
13: 00007FF5B03D1532
|
|
70
75
|
|
|
71
76
|
*/
|
|
72
77
|
|
package/twig.js
CHANGED
|
@@ -35,10 +35,13 @@ let current;
|
|
|
35
35
|
* @see {@link https://www.npmjs.com/package/libxmljs|libxmljs}
|
|
36
36
|
*/
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
*
|
|
40
|
-
* @
|
|
41
|
-
*
|
|
38
|
+
/*
|
|
39
|
+
* Other parsers I had a look at:
|
|
40
|
+
* {@link https://www.npmjs.com/package/sax-wasm|sax-wasm}: not a 'stream.Writable'
|
|
41
|
+
* {@link https://www.npmjs.com/package/@rubensworks/saxes|saxes}: not a 'stream.Writable'
|
|
42
|
+
* {@link https://www.npmjs.com/package/node-xml-stream|node-xml-stream}: should work, but not implemented
|
|
43
|
+
* {@link https://www.npmjs.com/package/saxes-stream|saxes-stream}: not a 'stream.Writable'
|
|
44
|
+
* {@link https://www.npmjs.com/package/xml-streamer|xml-streamer}: based on 'node-expat', does not add any benefit
|
|
42
45
|
*/
|
|
43
46
|
|
|
44
47
|
|