Update Nim version of treediff to build against Nim 1.0.

This commit is contained in:
Jonathan Bernard 2020-01-05 05:28:19 -06:00
parent c59a700cf9
commit bd41e2d2f5
3 changed files with 16 additions and 20 deletions

View File

@ -1,36 +1,32 @@
import md5 import md5, streams
import os import os
proc fileToMD5*(filename: string) : string = proc fileToMD5*(filename: string) : string =
const blockSize: int = 8192 const blockSize: int = 8192 # read files in 8KB chunnks
var var
c: MD5Context c: MD5Context
d: MD5Digest d: MD5Digest
f: File fs: FileStream
bytesRead: int = 0 buffer: string
buffer: array[blockSize, char]
byteTotal: int = 0
#read chunk of file, calling update until all bytes have been read #read chunk of file, calling update until all bytes have been read
try: try:
f = open(filename) fs = filename.open.newFileStream
md5Init(c) md5Init(c)
bytesRead = f.readBuffer(buffer.addr, blockSize) buffer = fs.readStr(blockSize)
while bytesRead > 0: while buffer.len > 0:
byteTotal += bytesRead md5Update(c, buffer, buffer.len)
md5Update(c, buffer, bytesRead) buffer = fs.readStr(blockSize)
bytesRead = f.readBuffer(buffer.addr, blockSize)
md5Final(c, d) md5Final(c, d)
except IOError: except IOError: echo("File not found.")
echo("File not found.")
finally: finally:
if f != nil: if fs != nil:
close(f) close(fs)
result = $d result = $d

View File

@ -30,7 +30,7 @@ proc init(p: ProgressWrapper, root: string, fileCount: int): void =
proc update(p: ProgressWrapper, count: int, file: string): void = proc update(p: ProgressWrapper, count: int, file: string): void =
if p.verbosity > very_quiet: if p.verbosity > very_quiet:
p.impl.updateProgress(count, file[(file.high - 15)..file.high]) p.impl.updateProgress(count, file[max(file.high - 15, 0)..file.high])
proc finish(p: ProgressWrapper): void = proc finish(p: ProgressWrapper): void =
if p.verbosity > very_quiet: if p.verbosity > very_quiet:
@ -232,7 +232,7 @@ Options:
""" """
let args = docopt(doc, version = "treediff v1.4.3") let args = docopt(doc, version = "treediff v1.4.5")
var verbosity = normal var verbosity = normal
if args["--quiet"]: verbosity = quiet if args["--quiet"]: verbosity = quiet

View File

@ -1,5 +1,5 @@
# Package # Package
version = "1.4.3" version = "1.4.5"
author = "Jonathan Bernard (jdb@jdb-labs.com)" author = "Jonathan Bernard (jdb@jdb-labs.com)"
description = "Utility to generate diffs of full directory trees." description = "Utility to generate diffs of full directory trees."
license = "BSD" license = "BSD"
@ -7,4 +7,4 @@ bin = @["treediff"]
srcDir = "src/main/nim" srcDir = "src/main/nim"
# Dependencies # Dependencies
requires: @["nim >= 0.13.0", "docopt >= 0.1.0", "console_progress >= 1.2.1"] requires: @["nim >= 1.0.4", "docopt >= 0.6.8", "console_progress >= 1.2.1"]