+ // Attempts to read existing metadata. Otherwise generates new set.
+
+ async _getMetadata() {
+
+ const metadataTarget = join(this.postsDirectory, '0', internals.kMetadataFilename);
+
+ try {
+ internals.debuglog(`Looking for metadata at ${metadataTarget}`);
+ return await readFile(metadataTarget);
+ }
+ catch (e) {
+ internals.debuglog(`Metadata not found or unreadable. Generating new set.`);
+ const createdOn = Date.now();
+ const metadata = {
+ id: String(createdOn),
+ createdOn
+ };
+
+ return JSON.stringify(metadata, null, 2);
+ }
+ }
+
+ // 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, metadata);
+ }
+