MCPcopy Index your code
hub / github.com/totaljs/framework / addNodeFree

Function addNodeFree

graphdb.js:204–234  ·  view source on GitHub ↗
(self, meta, callback)

Source from the content-addressed store, hash-verified

202}
203
204function addNodeFree(self, meta, callback) {
205
206 if (!meta.type.findfreeslots) {
207 addNode(self, meta, callback);
208 return;
209 }
210
211 findDocumentFree(self, meta.type.pageindex, function(err, documentindex, pageindex) {
212
213 if (!documentindex) {
214 meta.type.findfreeslots = false;
215 addNode(self, meta, callback);
216 return;
217 }
218
219 var buffer = U.createBufferSize(self.header.documentsize);
220 buffer.writeUInt8(meta.typeid, 0); // type
221 buffer.writeUInt8(meta.type.index, 1); // index
222 buffer.writeUInt32LE(pageindex, 3); // pageindex
223 buffer.writeUInt8(meta.state || STATE_UNCOMPRESSED, 2); // state
224 buffer.writeUInt32LE(meta.relationindex || 0, 7); // relationindex
225 buffer.writeUInt32LE(meta.parentindex || 0, 11); // parentindex
226 buffer.writeUInt16LE(meta.size, 15);
227 meta.data && meta.data.copy(buffer, DATAOFFSET);
228
229 Fs.write(self.fd, buffer, 0, buffer.length, offsetDocument(self, documentindex), function() {
230 meta.type.locked = false;
231 callback(null, documentindex, pageindex);
232 });
233 });
234}
235
236function addNode(self, meta, callback) {
237

Callers 1

addDocumentFunction · 0.85

Calls 4

addNodeFunction · 0.85
findDocumentFreeFunction · 0.85
offsetDocumentFunction · 0.85
callbackFunction · 0.85

Tested by

no test coverage detected