fix: set ZSTD Frame_Content_Size per record#203
Merged
Conversation
yzqzss
commented
Jun 28, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the Zstandard WARC writer to ensure each compressed WARC record is written as a ZSTD frame that includes the spec-required Frame_Content_Size, addressing issue #202 and improving spec compliance for larger records.
Changes:
- Introduces a
sizedZstdWriterwrapper to set ZSTDFrame_Content_Sizeper record. - Updates
Writer.WriteRecordto serialize a full record (header + body + trailer) and pre-set the compressor content size before encoding. - Adds an end-to-end test that parses produced ZSTD frames and asserts
Frame_Content_SizeandContent_Checksumare present.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| zstd_writer.go | Adds a ZSTD encoder wrapper that can set Frame_Content_Size for the next frame/record. |
| write.go | Serializes records into a single reader stream and sets per-record ZSTD content size before writing. |
| write_zstd_e2e_test.go | Adds e2e coverage asserting generated ZSTD frames include required header fields and are checksum-verified. |
| utils.go | Switches getContentLength return type to int64 and updates ZSTD writer construction to use the new wrapper. |
| dialer.go | Updates Content-Length header formatting to match int64 size handling. |
| dedupe.go | Updates record size parsing/storage to int64. |
Comments suppressed due to low confidence (1)
utils.go:208
- getContentLength() currently seeks and reads the full in-memory buffer into a new bytes.Buffer to compute the size. That has two concrete downsides: (1) it can move the underlying read cursor (callers that call getContentLength twice can get 0 the second time for in-memory records), and (2) it forces an O(n) read+copy even though spooledtempfile already exposes Len() for an O(1) size check. Prefer rwsc.Len() and only fall back to the current seek+read/stat behavior if Len() fails.
func getContentLength(rwsc spooledtempfile.ReadWriteSeekCloser) int64 {
// If the FileName leads to no existing file, it means that the SpooledTempFile
// never had the chance to buffer to disk instead of memory, in which case we can
// just read the buffer (which should be <= 2MB) and return the length
if rwsc.FileName() == "" {
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
yzqzss
added a commit
to saveweb/gowarc
that referenced
this pull request
Jun 28, 2026
NGTmeaty
approved these changes
Jul 2, 2026
Collaborator
Author
|
Sorry I missed your comments, GitHub didn't send me a notification for some reasons :( |
Collaborator
|
No worries, I meant to message you as well, oops! |
NGTmeaty
approved these changes
Jul 6, 2026
NGTmeaty
left a comment
Collaborator
There was a problem hiding this comment.
Looks great! I'll get this merged in tonight!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
close: #202
The unitest was written by AI.