+ // Attempts to read existing metadata. Otherwise generates new set.
+
+ async _getMetadata(index = 0) {
+
+ const metadataTarget = join(this.postsDirectory, String(index), internals.kMetadataFilename);
+
+ try {
+ internals.debuglog(`Looking for metadata at ${metadataTarget}`);
+ return JSON.parse(await readFile(metadataTarget, { encoding: 'utf8' }));
+ }
+ catch (e) {
+ internals.debuglog(`Metadata not found or unreadable. Generating new set.`);
+ const createdOn = Date.now();
+ const metadata = {
+ id: String(createdOn),
+ createdOn
+ };
+
+ return metadata;
+ }
+ }
+
+ // Writes metadata. Assumes post 0 since it only gets written
+ // on create
+
+ async _writeMetadata(metadata) {
+
+ const metadataTarget = join(this.postsDirectory, '0', internals.kMetadataFilename);
+ internals.debuglog(`Writing ${metadataTarget}`);
+ await writeFile(metadataTarget, JSON.stringify(metadata, null, 2));
+ }
+