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 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
@@ -5,7 +5,7 @@
5
5
  },
6
6
  "name": "xml-twig",
7
7
  "description": "Node module for processing huge XML documents in tree mode",
8
- "version": "1.3.10",
8
+ "version": "1.3.12",
9
9
  "main": "twig.js",
10
10
  "directories": {
11
11
  "doc": "doc"
@@ -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 NE = 0;
6
- console.log('Starting...')
7
- let parser = twig.createParser([{ tag: 'subsession', function: anyHandler }], { method: 'expat' })
8
- let reader = fs.createReadStream(`${__dirname}/20231019015552.1-MSRAN.xml`);
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 anyHandler(elt) {
12
- NE++;
13
- if (NE % 5 === 0) {
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
- 5 NE
35
- Memory usage by rss, 1070.65 MiB
36
- Memory usage by heapTotal, 1025.37 MiB
37
- Memory usage by heapUsed, 989.72 MiB
38
- Memory usage by external, 1.24 MiB
39
- Memory usage by arrayBuffers, 0.83 MiB
40
- 10 NE
41
- Memory usage by rss, 2816.7 MiB
42
- Memory usage by heapTotal, 2760.62 MiB
43
- Memory usage by heapUsed, 2690.95 MiB
44
- Memory usage by external, 1.42 MiB
45
- Memory usage by arrayBuffers, 1.02 MiB
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
- [6508:00000223570D04D0] 20692 ms: Scavenge 4034.0 (4122.1) -> 4032.4 (4135.1) MB, 13.7 / 0.0 ms (average mu = 0.431, current mu = 0.348) allocation failure;
50
- [6508:00000223570D04D0] 23749 ms: Mark-sweep 4046.7 (4135.1) -> 4044.6 (4150.4) MB, 3030.4 / 0.0 ms (average mu = 0.250, current mu = 0.055) allocation failure; scavenge might not succeed
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: 00007FF7BCDB9E7F node_api_throw_syntax_error+175967
57
- 2: 00007FF7BCD40C06 SSL_get_quiet_shutdown+65750
58
- 3: 00007FF7BCD41FC2 SSL_get_quiet_shutdown+70802
59
- 4: 00007FF7BD7DA214 v8::Isolate::ReportExternalAllocationLimitReached+116
60
- 5: 00007FF7BD7C5572 v8::Isolate::Exit+674
61
- 6: 00007FF7BD6473CC v8::internal::EmbedderStackStateScope::ExplicitScopeForTesting+124
62
- 7: 00007FF7BD6445EB v8::internal::Heap::CollectGarbage+3963
63
- 8: 00007FF7BD65A823 v8::internal::HeapAllocator::AllocateRawWithLightRetrySlowPath+2099
64
- 9: 00007FF7BD65B0CD v8::internal::HeapAllocator::AllocateRawWithRetryOrFailSlowPath+93
65
- 10: 00007FF7BD66A903 v8::internal::Factory::NewFillerObject+851
66
- 11: 00007FF7BD35BEB5 v8::internal::DateCache::Weekday+1349
67
- 12: 00007FF7BD8778B1 v8::internal::SetupIsolateDelegate::SetupHeap+558193
68
- 13: 00007FF73D9F10A1
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
- * @external sax-wasm
40
- * @todo Not yet implemented, maybe later. Not sure if `WritableStream` is supported
41
- * @see {@link https://www.npmjs.com/package/sax-wasm|sax-wasm}
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