File tree Expand file tree Collapse file tree 1 file changed +6
-1
lines changed Expand file tree Collapse file tree 1 file changed +6
-1
lines changed Original file line number Diff line number Diff line change @@ -128,6 +128,7 @@ class VectorDatabase {
128128 out.write (reinterpret_cast <const char *>(&idx), sizeof (idx));
129129 content.write (out);
130130 }
131+ out.close ();
131132 }
132133
133134 void loadIndex (const std::string& location) {
@@ -140,9 +141,13 @@ class VectorDatabase {
140141 int idx;
141142 T content;
142143 in.read (reinterpret_cast <char *>(&idx), sizeof (idx));
144+ if (in.eof ()) {
145+ break ;
146+ }
143147 content.read (in);
144148 m_documents[idx] = content;
145149 }
150+ in.close ();
146151 }
147152
148153private:
@@ -160,7 +165,7 @@ struct Document {
160165 size_t strSize = content.size ();
161166
162167 out.write (reinterpret_cast <const char *>(&strSize), sizeof (strSize));
163- out.write (content.data (), content. size () * sizeof (char ));
168+ out.write (content.data (), strSize * sizeof (char ));
164169 }
165170
166171 void read (std::istream& in) {
You can’t perform that action at this time.
0 commit comments