Delivery pipelines

Files with the same name do not necessarily refer to the same file: use content hashing to identify inputs.

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

阅读文本 / Reading text
This paper uses synthetic samples to demonstrate the processing method. The code has been verified using examples in an isolated environment; this does not guarantee effectiveness for all real files or products. Before processing important files, please retain the original copies and verify them against the boundaries and acceptance criteria specified in the text. 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. Files with the same name may have different contents, and even renamed files can have identical byte sequences. Content hashing is suitable for establishing version‑to‑version relationships, but it should not be assigned meanings it does not possess. leaves a byte fingerprint for the input SHA-256 Computes a digest based on the file’s bytes. Large files can be read in chunks without needing to load the entire file into memory. The hash result is independent of the chunk size; chunking is merely a reading strategy and does not constitute part of the file’s identity. The memory stream below is a synthetic sample and does not contain any real documents. is implemented using the same content with different chunks to verify 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") function reads from the current stream position. Before making a formal call, it should be confirmed whether the stream is at the beginning; one must not compute and designate it as the “hash of the entire file” immediately after the parser has already read part of it. The most reliable approach is to open a read-only input stream separately, or explicitly reset a seekable stream. bytes being identical does not necessarily mean the contents are identical; there is a distinction case How might the hash change? How to explain only changes the filename remains unchanged name does not participate in the byte digest PDF metadata was rewritten changes pages may look the same or they may differ resaves the compressed package changes compression parameters or timestamps can affect byte translated into another language typically changes input and output should be recorded separately as Do not use hashing as an authentication credential knowing a file digest does not imply the right to download it, nor does it confer copyright ownership. Cross-tenant deduplication may also reveal whether “a particular file already exists.” Even after a cache hit, access control must still be enforced, and the source, tenant, and processing policy must be recorded in the business logs. Translation list starts here submits the file to OmniDoc (Product Entry) records the input summary before processing, logs the output summary after downloading the translation, and then associates the language and terminology version. This way, when a colleague says “the results are incorrect,” you can first confirm that both parties are reviewing the same set of files, without having to go around multiple final filename guessing. Reference: Python hashlib 。 - 1 -
Updated 2026-10-08