MCPcopy Create free account
hub / github.com/totaljs/framework / finish

Function finish

graphdb.js:1624–1681  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1622 var totaldocuments = 0;
1623
1624 var finish = function() {
1625
1626 var buf = U.createBufferSize(HEADERSIZE);
1627 Fs.read(fd, buf, 0, buf.length, 0, function() {
1628
1629 // ==== DB:HEADER (7000b)
1630 // name (30b) = from: 0
1631 // version (1b) = from: 30
1632 // pages (4b) = from: 31
1633 // pagesize (2b) = from: 35
1634 // pagelimit (2b) = from: 37
1635 // documents (4b) = from: 39
1636 // documentsize (2b) = from: 43
1637 // classindex (1b) = from: 45
1638 // relationindex (1b) = from: 46
1639 // relationnodeindex = from: 47
1640 // classes + relations = from: 51
1641
1642 // buf.
1643
1644 buf.writeUInt32LE(pageindex > 0 ? (pageindex - 1) : 0, 31);
1645 buf.writeUInt32LE(totaldocuments, 39);
1646 buf.writeUInt16LE(meta.documentsize, 43);
1647
1648 var obj = {};
1649 obj.c = []; // classes
1650 obj.r = []; // relations
1651
1652 for (var i = 0; i < self.header.classindex; i++) {
1653 var item = self.$classes[i + 1];
1654 var schema = meta.classes[i + 1];
1655 obj.c.push({ n: item.name, i: item.index, p: item.pageindex, r: schema ? schema.raw : item.schema.raw, d: item.documentindex });
1656 }
1657
1658 for (var i = 0; i < self.header.relationindex; i++) {
1659 var item = self.$relations[i + 1];
1660 obj.r.push({ n: item.name, i: item.index, p: item.pageindex, b: item.both ? 1 :0, d: item.documentindex });
1661 }
1662
1663 buf.writeUInt8(self.header.classindex, 45);
1664 buf.writeUInt8(self.header.relationindex, 46);
1665 buf.writeUInt32LE(self.header.relationpageindex, 47);
1666 buf.write(JSON.stringify(obj), 51);
1667
1668 Fs.write(fd, buf, 0, buf.length, 0, function() {
1669 // console.log(pageindex, meta.documentsize, totaldocuments);
1670 Fs.close(fd, function() {
1671 Fs.close(self.fd, function() {
1672 Fs.copyFile(self.filename, self.filename.replace(/\.gdb$/, NOW.format('_yyyyMMddHHmm') + '.gdp'), function() {
1673 Fs.rename(self.filename + '-tmp', self.filename, function() {
1674 callback(null);
1675 });
1676 });
1677 });
1678 });
1679 });
1680 });
1681 };

Callers 1

processFunction · 0.70

Calls 1

callbackFunction · 0.85

Tested by

no test coverage detected