(self, relid, callback)
| 802 | |
| 803 | // Finds a free space for new relation in "pushRelationDocument" |
| 804 | function findRelationDocument(self, relid, callback) { |
| 805 | |
| 806 | if (!relid) { |
| 807 | callback(null, 0); |
| 808 | return; |
| 809 | } |
| 810 | |
| 811 | var offset = offsetDocument(self, relid); |
| 812 | var buf = U.createBufferSize(self.header.documentsize); |
| 813 | |
| 814 | Fs.read(self.fd, buf, 0, buf.length, offset, function(err, size) { |
| 815 | |
| 816 | if (err || !size) { |
| 817 | callback(err, 0); |
| 818 | return; |
| 819 | } |
| 820 | |
| 821 | var count = buf.readUInt16LE(15); |
| 822 | if (count + 1 > self.header.relationlimit) { |
| 823 | // Checks if the relation index has next relation |
| 824 | |
| 825 | if (relid === buf.readUInt32LE(7)) |
| 826 | return; |
| 827 | |
| 828 | relid = buf.readUInt32LE(7); |
| 829 | if (relid) |
| 830 | setImmediate(findRelationDocument, self, relid, callback); |
| 831 | else |
| 832 | callback(null, 0); |
| 833 | } else { |
| 834 | // Free space for this relation |
| 835 | callback(null, relid); |
| 836 | } |
| 837 | }); |
| 838 | } |
| 839 | |
| 840 | // Pushs "documentindex" to "index" document (document with all relations) |
| 841 | function pushRelationDocument(self, index, relation, documentindex, initializator, callback, between, recovered) { |
no test coverage detected