n3 1.17.5 → 1.17.6

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/lib/N3Store.js CHANGED
@@ -13,6 +13,9 @@ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return
13
13
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
14
14
  // **N3Store** objects store N3 quads by graph in memory.
15
15
 
16
+ const ITERATOR = Symbol('iter');
17
+
18
+ // ## Constructor
16
19
  class N3EntityIndex {
17
20
  constructor(options = {}) {
18
21
  this._id = 1;
@@ -382,9 +385,19 @@ class N3Store {
382
385
  const stream = new _readableStream.Readable({
383
386
  objectMode: true
384
387
  });
385
- stream._read = () => {
386
- for (const quad of this.readQuads(subject, predicate, object, graph)) stream.push(quad);
387
- stream.push(null);
388
+ const iterable = this.readQuads(subject, predicate, object, graph);
389
+ stream._read = size => {
390
+ while (size-- > 0) {
391
+ const {
392
+ done,
393
+ value
394
+ } = iterable.next();
395
+ if (done) {
396
+ stream.push(null);
397
+ return;
398
+ }
399
+ stream.push(value);
400
+ }
388
401
  };
389
402
  return this.remove(stream);
390
403
  }
@@ -773,9 +786,20 @@ class DatasetCoreAndReadableStream extends _readableStream.Readable {
773
786
  get size() {
774
787
  return this.filtered.size;
775
788
  }
776
- _read() {
777
- for (const quad of this) this.push(quad);
778
- this.push(null);
789
+ _read(size) {
790
+ if (size > 0 && !this[ITERATOR]) this[ITERATOR] = this[Symbol.iterator]();
791
+ const iterable = this[ITERATOR];
792
+ while (size-- > 0) {
793
+ const {
794
+ done,
795
+ value
796
+ } = iterable.next();
797
+ if (done) {
798
+ this.push(null);
799
+ return;
800
+ }
801
+ this.push(value);
802
+ }
779
803
  }
780
804
  add(quad) {
781
805
  return this.filtered.add(quad);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n3",
3
- "version": "1.17.5",
3
+ "version": "1.17.6",
4
4
  "description": "Lightning fast, asynchronous, streaming Turtle / N3 / RDF library.",
5
5
  "author": "Ruben Verborgh <ruben.verborgh@gmail.com>",
6
6
  "keywords": [
package/src/N3Store.js CHANGED
@@ -4,6 +4,9 @@ import { default as N3DataFactory, termToId, termFromId } from './N3DataFactory'
4
4
  import namespaces from './IRIs';
5
5
  import { isDefaultGraph } from './N3Util';
6
6
 
7
+ const ITERATOR = Symbol('iter');
8
+
9
+ // ## Constructor
7
10
  export class N3EntityIndex {
8
11
  constructor(options = {}) {
9
12
  this._id = 1;
@@ -386,10 +389,16 @@ export default class N3Store {
386
389
  removeMatches(subject, predicate, object, graph) {
387
390
  const stream = new Readable({ objectMode: true });
388
391
 
389
- stream._read = () => {
390
- for (const quad of this.readQuads(subject, predicate, object, graph))
391
- stream.push(quad);
392
- stream.push(null);
392
+ const iterable = this.readQuads(subject, predicate, object, graph);
393
+ stream._read = size => {
394
+ while (size-- > 0) {
395
+ const { done, value } = iterable.next();
396
+ if (done) {
397
+ stream.push(null);
398
+ return;
399
+ }
400
+ stream.push(value);
401
+ }
393
402
  };
394
403
 
395
404
  return this.remove(stream);
@@ -805,10 +814,18 @@ class DatasetCoreAndReadableStream extends Readable {
805
814
  return this.filtered.size;
806
815
  }
807
816
 
808
- _read() {
809
- for (const quad of this)
810
- this.push(quad);
811
- this.push(null);
817
+ _read(size) {
818
+ if (size > 0 && !this[ITERATOR])
819
+ this[ITERATOR] = this[Symbol.iterator]();
820
+ const iterable = this[ITERATOR];
821
+ while (size-- > 0) {
822
+ const { done, value } = iterable.next();
823
+ if (done) {
824
+ this.push(null);
825
+ return;
826
+ }
827
+ this.push(value);
828
+ }
812
829
  }
813
830
 
814
831
  add(quad) {