private long updatebody(long position, IndexDocument doc, string newbody, string meta) { int bodylen = 0; var bodybytes = this.Encoding.GetBytes(newbody); if (bodybytes != null) { bodylen = bodybytes.Length; } if (bodylen < doc.BodyBufferLen) { this.DataStream.Position = position + 6; this.DataStream.Write(BitConverter.GetBytes(bodylen), 0, 4); //write body bytes. this.DataStream.Position = position + 14 + doc.MetaLen; this.DataStream.Write(bodybytes, 0, bodylen); return(position); } else { return(AddDoc(newbody, meta)); } }
public IndexDocument LoadDoc(long Position) { lock (_locker) { byte[] header = new byte[14]; this.DataStream.Position = Position; this.DataStream.Read(header, 0, 14); if (header[0] != 10 || header[1] != 13) { return(null); } int metalen = BitConverter.ToInt32(header, 2); int bodylen = BitConverter.ToInt32(header, 6); int bodybufferlen = BitConverter.ToInt32(header, 10); int totallen = metalen + bodylen; byte[] content = new byte[totallen]; this.DataStream.Position = Position + 14; this.DataStream.Read(content, 0, totallen); IndexDocument doc = new IndexDocument() { MetaLen = metalen, BodyBufferLen = bodybufferlen, BodyLen = bodylen }; if (metalen > 0) { doc.Meta = this.Encoding.GetString(content, 0, metalen); } if (bodylen > 0) { doc.Body = this.Encoding.GetString(content, metalen, bodylen); } return(doc); } }