惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

量子位
D
DataBreaches.Net
Microsoft Security Blog
Microsoft Security Blog
V
Visual Studio Blog
GbyAI
GbyAI
美团技术团队
云风的 BLOG
云风的 BLOG
大猫的无限游戏
大猫的无限游戏
小众软件
小众软件
博客园 - 叶小钗
Engineering at Meta
Engineering at Meta
博客园 - 三生石上(FineUI控件)
N
Netflix TechBlog - Medium
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
G
Google Developers Blog
博客园 - 【当耐特】
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
宝玉的分享
宝玉的分享
阮一峰的网络日志
阮一峰的网络日志
T
The Blog of Author Tim Ferriss
Y
Y Combinator Blog
U
Unit 42
P
Proofpoint News Feed
V
V2EX

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Gnoke SaveNative: A Durability Layer for the File System ...
Ekong Ikpe · 2026-05-03 · via DEV Community

Ekong Ikpe

I was building offline-first apps for the Gnoke Suite and ran into the same wall every time.

The File System Access API works beautifully — until your phone decides otherwise.

A background OS kill. A tab reload at the wrong moment. Ten concurrent writes racing for the same stream. Any of these silently drops your data. No error. No warning. Just gone.

The browser fantasy is: pick a folder, write files, done.

The mobile reality is: your process dies, your handle goes stale, and your writable stream errors out mid-write. 😬

So I built a survival layer around it.


Meet gnoke-savenative

A two-layer write pipeline for browser apps. Native filesystem first, IndexedDB shelf as instant fallback.

npm install gnoke-savenative

Enter fullscreen mode Exit fullscreen mode

import { saveNative } from 'gnoke-savenative';
import { openDB }     from 'idb';

// Mount once (user gesture required)
const handle = await saveNative.mount(openDB);
let workspace = { handle, db: await saveNative._db(openDB) };

// Write — native first, shelf if it fails
await saveNative.write(workspace, 'notes.txt', 'Hello world');

// After reload — wake restores handle and auto-flushes shelf
workspace = await saveNative.wake(openDB);

Enter fullscreen mode Exit fullscreen mode


The Survival Loop

Every write has a guaranteed outcome — it's either on disk or in the shelf.

write()
  ↓ native success → file on disk ✓
  ↓ native failure → shelved in IndexedDB

wake() after reload
  ↓ handle restored
  ↓ _flush() drains shelf → file on disk ✓

Enter fullscreen mode Exit fullscreen mode

Writes are never dropped — only delayed. Recovery is automatic. Visibility is optional via hooks.


What makes it mobile-ready 📱

On desktop, the File System Access API mostly just works. On mobile (tested on Infinix Android, Chrome), three things will break a naive implementation:

1. OS background kills

The browser process dies. The handle survives in IndexedDB. But the write that was in-flight is gone. The shelf catches it.

2. Stale writable streams

Open a stream, come back after the OS has changed something on disk — the stream errors. Every write goes through a fresh createWritable() call.

3. Concurrent write races — this is where most implementations silently fail 🤷

The File System Access API does not serialize concurrent writes to the same file. Fire ten writes at once and they fight over the same stream — most fail with no error. gnoke-savenative maintains a per-filename queue so writes process in strict order. This is not retry logic — it's guaranteed ordering backed by a persistent fallback. v0.1.1 was specifically a concurrency patch after stress testing exposed false shelf activations on clean writes.


The API

saveNative.mount(openDB)                    // pick folder, stash handle
saveNative.wake(openDB)                     // restore handle, auto-flush shelf
saveNative.write(workspace, name, content)  // queued write with shelf fallback

Enter fullscreen mode Exit fullscreen mode

Optional hooks for UI feedback:

saveNative.onWriteFailure  = (name, err)   => { /* shelved */ };
saveNative.onFlushProgress = (done, total) => { /* draining */ };
saveNative.onFlushComplete = (count)       => { /* recovered */ };

Enter fullscreen mode Exit fullscreen mode


How it was built

This came out of a real stress test — a Ghost Editor testbench on a real Infinix device, with hard reloads, app switches, and 10 concurrent writes fired at once.

The pattern is essentially a write-ahead buffer with eventual durability: attempt the native write, fall back to the shelf on failure, replay on wake. The same principle behind WAL in database engines — applied to the browser filesystem. 🧠

v0.1 proved the shelf worked.

v0.1.1 eliminated false shelf activations under concurrent writes.

After the stress test showed zero shelf activations on clean concurrent writes, it was ready to ship. ✅


Try it

👉 github.com/edmundsparrow/gnoke-savenative

Zero dependencies (brings your own openDB). MIT licensed. Vanilla JS ES module.

Drop it in any project via CDN — no npm, no build step:

<!-- ES module -->
<script type="module">
  import { saveNative } from 'https://cdn.jsdelivr.net/gh/edmundsparrow/gnoke-savenative/gnoke-savenative.js';
  import { openDB }     from 'https://unpkg.com/idb?module';
</script>

<!-- Or plain script tag — window.saveNative available globally -->
<script src="https://cdn.jsdelivr.net/gh/edmundsparrow/gnoke-savenative/gnoke-savenative.js"></script>

Enter fullscreen mode Exit fullscreen mode

— Edmund Sparrow, Gnoke Suite