From e2ec56d7c568860cdd85569054cb1bef1e1c13db Mon Sep 17 00:00:00 2001 From: Jelmer Snoeck Date: Sun, 8 Nov 2015 16:12:59 +0000 Subject: Compare: make `CompareBytes` exported. All the "magic" of reference comparison happens within the `CompareBytes` function. Reading a file (with `ioutil.ReadFile`) gives you an array of bytes and gofpdf supports writing to a byte buffer, where we can easily get the bytes from. Exporting `CompareBytes` would make it possible to use this core functionality instead of having to convert the data into `io.Reader`. --- compare.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'compare.go') diff --git a/compare.go b/compare.go index 64cad1f..edc1ae4 100644 --- a/compare.go +++ b/compare.go @@ -84,9 +84,9 @@ func checkBytes(pos int, sl1, sl2 []byte) (eq bool) { return } -// compareBytes compares the bytes referred to by sl1 with those referred to by +// CompareBytes compares the bytes referred to by sl1 with those referred to by // sl2. Nil is returned if the buffers are equal, otherwise an error. -func compareBytes(sl1, sl2 []byte) (err error) { +func CompareBytes(sl1, sl2 []byte) (err error) { var posStart, posEnd, len1, len2, length int var diffs bool @@ -122,7 +122,7 @@ func ComparePDFs(rdr1, rdr2 io.Reader) (err error) { if err == nil { _, err = b2.ReadFrom(rdr2) if err == nil { - err = compareBytes(b1.Bytes(), b2.Bytes()) + err = CompareBytes(b1.Bytes(), b2.Bytes()) } } return @@ -139,7 +139,7 @@ func ComparePDFFiles(file1Str, file2Str string) (err error) { if err == nil { sl2, err = ioutil.ReadFile(file2Str) if err == nil { - err = compareBytes(sl1, sl2) + err = CompareBytes(sl1, sl2) } else { // Second file is missing; treat this as success err = nil -- cgit v1.2.1-24-ge1ad