/* Tests for libfossil/th1ish Buffer compression... */

const inFile = __FILE
const szFile = Fossil.file.size(inFile)
var b = api.Buffer(szFile+2)
b.readFile(inFile)
const szUncompressed = b.length()
const shaA = [b.sha1]
print(__SRC,' ',inFile,' uncompressed size: ',
    szUncompressed, ' SHA1: ', shaA)
assert !b.isCompressed()
assert szUncompressed === szFile
b.compress()
assert b.isCompressed()
const shaZ = [b.sha1]
const szCompressed = b.length()
print(__SRC,' ',inFile,' compressed size: ',
szCompressed, ' SHA1: ', shaZ)
assert szCompressed < szUncompressed
var zFile = __FILE+'.compressed';
b.writeToFile(zFile)
assert b.length() === Fossil.file.size(zFile)
b.length(0) // b/c readFromFile() will _append_ to it.
b.readFile(zFile)
assert b.isCompressed()
assert szCompressed === b.length()
b.uncompress()
assert !b.isCompressed()
assert szUncompressed === b.length()
assert b.length() === szFile
b.writeToFile(__FILE+'.uncompressed')
