Skip to content

feature nvs: blob upload#110

Merged
Jason2866 merged 3 commits into
mainfrom
nvs_blob_upload
May 14, 2026
Merged

feature nvs: blob upload#110
Jason2866 merged 3 commits into
mainfrom
nvs_blob_upload

Conversation

@Jason2866
Copy link
Copy Markdown
Owner

@Jason2866 Jason2866 commented May 14, 2026

Summary by CodeRabbit

  • New Features
    • Added support for uploading and replacing blob data from local files in the Blobs dialog. Users can select a file, confirm the replacement, and the blob data is updated accordingly.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 14, 2026

Warning

Rate limit exceeded

@Jason2866 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 26 minutes and 32 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 0532dd4f-15d3-47e6-af1f-577a57235712

📥 Commits

Reviewing files that changed from the base of the PR and between fb9d7d8 and 33d5dcd.

📒 Files selected for processing (1)
  • js/nvs-editor.js
📝 Walkthrough

Walkthrough

This PR adds blob upload and replacement functionality to the NVS editor's Blobs dialog. Users can select a local file to replace an existing blob, and the editor distributes the file bytes across the blob's data chunk entries, updates size and CRC checksums, synchronizes the blob index if present, re-parses the NVS data, and refreshes the UI.

Changes

Blob Upload and Replacement

Layer / File(s) Summary
Upload button and blob replacement workflow
js/nvs-editor.js
Added upload button to the Blobs dialog UI and implemented the complete replacement workflow: clicking the button opens a file picker, the handler confirms the file size fits the blob, calls _uploadBlobToNVS() to distribute bytes into data chunks while updating per-entry size fields and data CRC, optionally updates the blob index's totalSize and header CRC, then marks the editor modified and re-parses, re-renders, and refreshes the write button state.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A blob now flies from disk to NVS,
Bytes dance through chunks in one swift kiss,
CRCs bloom and checksums align,
The rabbit hops—a feature fine! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feature nvs: blob upload' clearly and specifically describes the main change: adding blob upload functionality to the NVS editor.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch nvs_blob_upload

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@js/nvs-editor.js`:
- Around line 1815-1892: The loop over dataEntries must track how many chunk
slots are actually populated and erase any trailing unused slots instead of
leaving them as zero-sized orphan chunks; inside the for (const { item, maxSize
} of dataEntries) loop, increment a populatedChunks counter when writeLen > 0,
and when writeLen === 0 invoke the same erase/bitmap-zeroing logic used by
_deleteEntry (wipe the slot payload/header and clear its bitmap flag) rather
than only setting size=0 and header CRC; after the loop, if
blob.indexEntry/datatype === 0x48 update its totalSize (at idxOff + 24) and also
write the new chunkCount (at idxOff + 28) to populatedChunks, then recompute and
write the header CRC via NVSEditor.crc32Header (as currently done) so the index
entry and bitmap stay consistent with actual populated chunks.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5fde81a0-4d00-4e6a-a788-5a90411ca36b

📥 Commits

Reviewing files that changed from the base of the PR and between 85b22de and fb9d7d8.

📒 Files selected for processing (1)
  • js/nvs-editor.js

Comment thread js/nvs-editor.js
@Jason2866
Copy link
Copy Markdown
Owner Author

@coderabbitai is the NVS blob write solid with commit 3f7e648

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 14, 2026

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

Let me read the implementation carefully before answering.


🏁 Script executed:

#!/bin/bash
# Read the nvs-editor.js file to inspect the blob upload implementation
fd -e js nvs-editor | head -5
cat js/nvs-editor.js

Length of output: 65408


@Jason2866 After reading the full _uploadBlobToNVS implementation carefully, the core logic is solid for all typical cases. Here is a detailed breakdown:


✅ What's correct

Area Assessment
Capacity check (item.span - 1) * 32 correctly reflects physical bytes available (not prior usage)
Data write order Payload written first, then segData is read from the already-updated buffer → CRC covers new data ✓
Size field update +24/+25 (u16 little-endian), +26/+27 forced to 0xFF
Data CRC Written at +28 after new payload is in place ✓
Header CRC Recalculated after size field and data CRC are already updated at +24..+31
Trailing chunk cleanup _deleteEntry zeros payload + header and sets bitmap to ERASED (0b00) — no orphan slots ✓
blob_index sync totalSize (u32 at +24), chunkCount (u8 at +28) both updated; chunkStart (+29) correctly untouched ✓
blob_index header CRC Recalculated after both fields are updated ✓
DataView with byteOffset Defensive and correct; safe for subarrays ✓
Re-parse + re-render Done after all mutations ✓

⚠️ Two edge cases worth knowing about

1. Empty file upload (0 bytes)
If a user uploads a 0-byte file, all data chunks get deleted via _deleteEntry, and the blob_index is left with totalSize=0, chunkCount=0. This is a valid degenerate state but creates an orphan index entry with no data — the NVS library on the ESP32 might not handle that gracefully. A simple guard would prevent it:

if (fileBytes.length === 0) {
  throw new Error("Cannot upload an empty file as blob replacement.");
}

2. span=1 blob_data entries (theoretical)
If a parsed blob_data entry somehow has span=1, maxSize would be 0, writeLen would be 0, and the entry would get deleted rather than written. However, this cannot occur in valid NVS — a blob_data entry always requires span ≥ 2 (1 header + at least 1 data slot). So in practice this path is unreachable.


Summary

The NVS blob write in commit 3f7e648 is solid for all real-world use: same-or-smaller file replacements across single or multi-chunk blobs, correct CRC chain throughout, and clean cleanup of unused trailing slots. The only practical hardening worth adding is a guard against 0-byte file uploads.

@Jason2866 Jason2866 merged commit c37ff64 into main May 14, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant