Add Attachment.deleteData

This commit is contained in:
Daniel Gasienica 2018-03-20 14:48:40 -04:00
parent 10afcf1bb0
commit 279b3f81c7

View file

@ -142,3 +142,29 @@ exports.loadData = (readAttachmentData) => {
return Object.assign({}, attachment, { data }); return Object.assign({}, attachment, { data });
}; };
}; };
// deleteData :: (RelativePath -> IO Unit)
// Attachment ->
// IO Unit
exports.deleteData = (deleteAttachmentData) => {
if (!isFunction(deleteAttachmentData)) {
throw new TypeError('`deleteAttachmentData` must be a function');
}
return async (attachment) => {
if (!exports.isValid(attachment)) {
throw new TypeError('`attachment` is not valid');
}
const hasDataInMemory = exports.hasData(attachment);
if (hasDataInMemory) {
return;
}
if (!isString(attachment.path)) {
throw new TypeError('`attachment.path` is required');
}
await deleteAttachmentData(attachment.path);
};
};