Same File Name, Different File: Identify Inputs by Hash

The client subsequently sent two documents, both titled final.pdf Which of the files has been translated? Relying on file names to answer this question is risky

Two files with the same name can hold different content, and the name alone will not tell you which one was translated. Teams that handle many versions of the same document often end up debating which copy is which. This guide shows how to fingerprint each input with a content hash so you can match files by their bytes instead of their names.

You will learn how to compute a SHA-256 digest, how to read a file consistently so the hash is reliable, and what a hash can and cannot tell you about the relationship between two versions. You will also see why a hash should never be treated as proof of access or ownership.

Note: This guide uses synthetic samples to show the method. Keep the original copies of important files, and check results against the boundaries and acceptance criteria that apply to your work before you rely on them.

How do you tell which same-named file was translated? The short answer

Compare the SHA-256 digest of each file's bytes, record it before processing, and never rely on the file name alone.

Your situationWhat to doWhy
Two files share a name such as final.pdfCompute a SHA-256 digest of each file's bytesThe name does not take part in the digest, so the hash tells the files apart
You need to know if a file changedCompare digests before and after processingByte-level changes alter the hash, and renaming alone does not
A file is largeRead it in chunksThe hash result does not depend on chunk size
You need to share a file recordLog the input and output summaries with language and terminology versionThe record shows both parties are reviewing the same files
Someone asks whether a file may be downloadedCheck access control and policy, not the hashA digest does not grant rights or prove ownership

Why file names cannot answer the question

The client later sent two documents, both titled final.pdf. Which one has been translated? Relying on file names to answer this is risky, for two reasons:

  • Different files can share a name. Two documents can carry the same title but contain different text.
  • Identical files can have different names. A renamed file can still have exactly the same bytes.

Content hashing is useful for establishing version-to-version relationships. Do not give it meanings it does not have.

Leave a byte fingerprint on every input

SHA-256 computes a digest from a file's bytes. You can use it to fingerprint each input before processing starts.

  • Large files can be read in chunks, so you do not need to load the whole file into memory.
  • The hash result is independent of chunk size. Chunking is only a reading strategy and is not part of the file's identity.
  • The example below uses a synthetic memory stream, not a real document.

Read the file the same way every time

import hashlib
from io import BytesIO

def digest(stream, chunk_size=65536):
    if type(chunk_size) is not int or chunk_size <= 0:
        raise ValueError("positive chunk size required")
    h = hashlib.sha256()
    while block := stream.read(chunk_size):
        h.update(block)
    return h.hexdigest()

raw = b"synthetic document version A\n"
a = digest(BytesIO(raw), 3)
assert a == digest(BytesIO(raw), 4096)
assert a == hashlib.sha256(raw).hexdigest()
assert a != digest(BytesIO(raw.replace(b"A", b"B")))
assert digest(BytesIO(b"")) == hashlib.sha256(b"").hexdigest()
try:
    digest(BytesIO(raw), 0)
except ValueError:
    pass
else:
    raise AssertionError("zero chunk must be rejected")

The hash function reads from the stream's current position. Before you compute a digest, confirm the stream is at the beginning. Do not compute the "hash of the entire file" right after a parser has already read part of it. The most reliable approaches are:

  1. Open a separate read-only input stream for hashing.
  2. Explicitly reset a seekable stream to its start before hashing.

Identical bytes versus identical content

Bytes being identical does not always mean the contents are identical, and bytes being different does not always mean the contents differ. Use this table to interpret what a changed or unchanged hash means:

CaseHow might the hash change?How to explain it
Only the file name changesRemains unchangedThe name does not take part in the byte digest
PDF metadata is rewrittenChangesPages may look the same or they may differ
A compressed package is resavedChangesCompression parameters or timestamps can affect the bytes
The document is translated into another languageTypically changesRecord the input and output separately, as different files

Do not treat a hash as a credential

Knowing a file's digest does not give you the right to download the file, and it does not confer copyright ownership. Keep these points in mind:

  • Access still needs checks. Even after a cache hit, enforce access control.
  • Deduplication can leak information. Cross-tenant deduplication may reveal whether a particular file already exists.
  • Log the context. Record the source, the tenant, and the processing policy in your business logs.

A simple logging workflow

Use the following steps to keep a clear record of every version:

  1. Submit the file to OmniDoc (Product Entry).
  2. Record the input summary before processing.
  3. Log the output summary after you download the translation.
  4. Associate the language and the terminology version with both records.

When a colleague says "the results are incorrect," you can first confirm that you are both reviewing the same set of files. You will not need to guess among several final file names.

Reference: Python hashlib

🎯 Which approach fits you?

If you need to tell two same-named files apart

Compute a SHA-256 digest of each file's bytes and compare the digests. Do not rely on the file name.

If you process very large files

Read them in chunks. The hash result stays the same regardless of chunk size.

If you share translated versions with a team

Log the input summary, the output summary, the language, and the terminology version for each file, so everyone reviews the same set.

❓ FAQ

1. Does renaming a file change its hash?

No. The file name does not take part in the byte digest, so a renamed file with identical bytes keeps the same hash.

2. Does a changed hash mean the content is different?

Not always. Rewritten PDF metadata or a resaved compressed package can change the bytes while the pages look the same, so explain each change in context.

3. Why must the stream be at the start before hashing?

The hash function reads from the current stream position. If a parser has already read part of the file, the digest will not represent the whole file.

4. Can I use the hash to decide who may download a file?

No. Knowing a digest does not grant download rights or copyright ownership. Enforce access control and record the source, tenant, and processing policy.

📝 Summary

Same-named files can hold different content, so match files by a SHA-256 digest of their bytes and log each input and output with its language and terminology version. Treat the hash as a way to identify files, not as proof of access or ownership.

Try it now: upload a document and get it translated with the layout intact

Updated 2026-11-29