import * as crypto from 'crypto' ; import { getMetadata } from '../utils/Metadata' ; import { IsModified } from '../exposed' ; import { BasicObject } from '../db' ; /**
 * Checks MD5 and eTags on the head of the currently persisted document, if it
 * exists. If they match, modified returns false. If they dont, it returns true.
 */ export class MD5IsModified implements IsModified { param body public static md5Hash ( body ) { return crypto . createHash ( 'md5' ) . update ( body ) . digest ( 'base64' ) ; } param documentToCheck param body public isModified ( documentToCheck , body ) { const metadata = getMetadata ( documentToCheck ) ; if ( metadata ) { const md5ToCheck = MD5IsModified . md5Hash ( body ) ; const md5Before = metadata . ContentMD5 ; return md5ToCheck !== md5Before ; } else { return true ; } } }