# Efficient file hashing

**URL:** <https://discourse.julialang.org/t/efficient-file-hashing/2859>\
**Category:** General Usage\
**Tags:** binaryio\
**Created:** [March 24, 2017, 1:20pm UTC](https://discourse.julialang.org/t/efficient-file-hashing/2859 "2017-03-24T13:20:31Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [March 24, 2017, 2:34pm UTC](https://discourse.julialang.org/t/efficient-file-hashing/2859/3 "2017-03-24T14:34:51Z")

</div>

If you just want a checksum, rather than a cryptographically secure hash, Julia 0.6 has a hardware-accelerated CRC-32c checksum function ([https://github.com/JuliaLang/julia/pull/18297](https://github.com/JuliaLang/julia/pull/18297)). Currently it is unexported/undocumented, but that will likely change in the future.

In the meantime, you can do:

```julia
Base.crc32c(read(filename))

```

to read in the whole file and compute the checksum. Alternatively, you can checksum it in chunks by something like:

```julia
function checksum(filename, blocksize=16384)
    crc = zero(UInt32)
    open(filename, "r") do f
        while !eof(f)
            crc = Base.crc32c(read(f, blocksize), crc)
        end
    end
    return crc
end

```

(The answer is independent of `blocksize`.)

_Update_: CRC32c checksums were [exported in Julia 0.7](https://github.com/JuliaLang/julia/pull/22274) and are now available in the [CRC32c stdlib](https://docs.julialang.org/en/v1/stdlib/CRC32c/). You can checksum a file with `using CRC32c; checksum = open(crc32c, filename)`.

---

_[View the full topic](https://discourse.julialang.org/t/efficient-file-hashing/2859)._
