(self, meta, callback)
| 234 | } |
| 235 | |
| 236 | function addNode(self, meta, callback) { |
| 237 | |
| 238 | // meta.typeid (1 CLASS, 2 RELATION) |
| 239 | // meta.type (link to type class/relation) |
| 240 | // meta.state |
| 241 | // meta.parentindex |
| 242 | // meta.relationindex |
| 243 | // meta.size |
| 244 | // meta.buffer |
| 245 | |
| 246 | var buf = U.createBufferSize(self.header.pagesize); |
| 247 | var offset = offsetPage(self, meta.type.pageindex); |
| 248 | |
| 249 | meta.type.locked = true; |
| 250 | |
| 251 | Fs.read(self.fd, buf, 0, buf.length, offset, function(err) { |
| 252 | |
| 253 | if (err) |
| 254 | throw err; |
| 255 | |
| 256 | if (buf[0] !== meta.typeid) |
| 257 | throw new Error('Not a class page'); |
| 258 | |
| 259 | if (!meta.type.private && buf[1] !== meta.type.index) |
| 260 | throw new Error('Not same class type'); |
| 261 | |
| 262 | // type : buf[0] |
| 263 | // index : buf[1] |
| 264 | // documents : buf.readUInt16LE(2) |
| 265 | // freeslots : buf[4] |
| 266 | // parentindex : readUInt32LE(5) |
| 267 | |
| 268 | var buffer = U.createBufferSize(self.header.documentsize); |
| 269 | buffer.writeUInt8(buf[0], 0); // type |
| 270 | buffer.writeUInt8(meta.type.index, 1); // index |
| 271 | buffer.writeUInt32LE(meta.type.pageindex, 3); // pageindex |
| 272 | buffer.writeUInt8(meta.state || STATE_UNCOMPRESSED, 2); // state |
| 273 | buffer.writeUInt32LE(meta.relationindex || 0, 7); // relationindex |
| 274 | buffer.writeUInt32LE(meta.parentindex || 0, 11); // parentindex |
| 275 | buffer.writeUInt16LE(meta.size, 15); |
| 276 | meta.data && meta.data.copy(buffer, DATAOFFSET); |
| 277 | |
| 278 | var documents = buf.readUInt16LE(2); |
| 279 | var documentsbuf = U.createBufferSize(2); |
| 280 | |
| 281 | documents++; |
| 282 | documentsbuf.writeUInt16LE(documents); |
| 283 | |
| 284 | Fs.write(self.fd, documentsbuf, 0, documentsbuf.length, offset + 2, function(err) { |
| 285 | |
| 286 | err && console.log('addNode.write.meta', err); |
| 287 | Fs.write(self.fd, buffer, 0, buffer.length, offset + self.header.pagesize + ((documents - 1) * self.header.documentsize), function(err) { |
| 288 | |
| 289 | err && console.log('addNode.write.data', err); |
| 290 | |
| 291 | // type (1b) = from: 0 |
| 292 | // index (1b) = from: 1 |
| 293 | // state (1b) = from: 2 |
no test coverage detected