(self, index, documentindex, callback, counter)
| 609 | |
| 610 | // Traverses all RELATIONS documents and remove specific "documentindex" |
| 611 | function remRelationAll(self, index, documentindex, callback, counter) { |
| 612 | |
| 613 | var buf = U.createBufferSize(self.header.pagelimit * self.header.documentsize); |
| 614 | var offset = offsetDocument(self, index); |
| 615 | |
| 616 | !counter && (counter = 0); |
| 617 | |
| 618 | Fs.read(self.fd, buf, 0, buf.length, offset, function(err, size) { |
| 619 | |
| 620 | if (err || !size) { |
| 621 | callback(null, counter); |
| 622 | return; |
| 623 | } |
| 624 | |
| 625 | // type (1b) = from: 0 |
| 626 | // index (1b) = from: 1 |
| 627 | // state (1b) = from: 2 |
| 628 | // pageindex (4b) = from: 3 |
| 629 | // relationindex (4b) = from: 7 (it's for relations between two documents in TYPE_RELATION page) |
| 630 | // parentindex (4b) = from: 11 |
| 631 | // size/count (2b) = from: 15 |
| 632 | // data = from: 17 |
| 633 | |
| 634 | var removed = []; |
| 635 | |
| 636 | while (true) { |
| 637 | |
| 638 | if (!buf.length) |
| 639 | break; |
| 640 | |
| 641 | index++; |
| 642 | |
| 643 | var data = buf.slice(0, self.header.documentsize); |
| 644 | |
| 645 | if ((data[0] !== TYPE_RELATION && data[0] !== TYPE_RELATION_DOCUMENT) || (data[2] === STATE_REMOVED)) { |
| 646 | buf = buf.slice(self.header.documentsize); |
| 647 | continue; |
| 648 | } |
| 649 | |
| 650 | var count = data.readUInt16LE(15); |
| 651 | var arr = []; |
| 652 | var is = false; |
| 653 | |
| 654 | for (var i = 0; i < count; i++) { |
| 655 | var off = DATAOFFSET + (i * 6); |
| 656 | var obj = {}; |
| 657 | obj.INDEX = data[off]; |
| 658 | obj.INIT = data[off + 1]; |
| 659 | obj.ID = data.readUInt32LE(off + 2); |
| 660 | if (obj.ID === documentindex) |
| 661 | is = true; |
| 662 | else |
| 663 | arr.push(obj); |
| 664 | } |
| 665 | |
| 666 | if (is) { |
| 667 | |
| 668 | var newcount = arr.length; |
no test coverage detected