Urgent.News

What's breaking now, across thousands of outlets.

Tech

My universal document converter learned that 'auto-detect' is a lie when the file extension lies

The idea behind the universal converter was simple: hand it any document, it figures out the type, converts to Markdown. No routing on the caller's side. One endpoint. The failure mode I didn't plan for: a PDF that arrives named report.docx . A user sent a contract scanned to PDF, but their pipeline renamed it with a .docx extension because "that's what the upload widget defaults to." My sniffing…

The universal document converter initially relied on auto-detect based on file extensions. However, this approach proved flawed when a PDF named report.docx was received. The initial sniffing logic, which checked the file extension first, led to the processing of binary noise from a PDF header instead of the intended Markdown output.

To rectify this, the converter stopped trusting file names and now relies on detecting magic bytes such as %PDF- for PDF files, PK\x03\x04 for OOXML formats like DOCX, and ID3 or \xFF\xFB for MP3 files. Extension remains a tiebreaker when magic bytes are ambiguous, which is rarely the case for the supported formats. Another mistake was underestimating the shared structure between EPUB and DOCX files, both being PK zips with XML payloads.

The converter initially rendered a Word document as "chapter 1: [Content_Types].xml," although technically accurate, this was practically useless. The third issue lies with plain text files. When magic bytes offer no clue, the default is to treat them as text/plain. This works well for .txt files but fails for files like CSVs, JSONs, or Python scripts that lack distinctive delimiters or structure in their initial bytes.

The converter now checks for these common delimiters and JSON structures before reverting to plain text. However, there exist certain types of files where it remains impossible to determine their nature without examining the entire content. The current behavior of the universal document-to-Markdown endpoint can be accessed at https://x402.freeq.one/tools/document_to_markdown.html, processing files through magic bytes first, structure sniffing second, extension as a secondary hint, and plain text as the last resort.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Vibecoding: Using Ambient Sound to Keep Your Code Flow Smooth

What is vibecoding? Vibecoding is a simple practice that pairs the auditory and visual atmosphere of your workspace with the act of programming.

  • Vibecoding combines auditory and visual cues with coding.
  • Ambient sound uses instrumental or low-key electronic music.
  • Consistent lighting and editor theme enhance concentration.

SpiderMonkey: Firefox's JavaScript Engine — JIT Compilation, GC, and Performance Tips

SpiderMonkey is Firefox's JavaScript engine — the component that parses, compiles, and executes JavaScript code. Understanding how it works helps you write better-performing JavaScript and understand…

  • SpiderMonkey powers Firefox JavaScript engine
  • Includes parser, bytecode compiler, interpreter, JIT compilers
  • JIT compilation upgrades code from interpreter to Ion/Warp JIT

Mitigating DB Lock Contention and Race Conditions in Asynchronous Webhook Ingestion

Mitigating DB Lock Contention and Race Conditions in Asynchronous Webhook Ingestion 1. The Production Reality: Why Check-Then-Act Fails Under Load In event-driven architectures, deduplicating…

  • Naive approach leads to Check-Then-Act race condition in webhook ingestion.
  • Three-tier defense pipeline proposed to mitigate race conditions and lock contention.
  • Unique constraint and idempotent no-op ensure true idempotency under concurrency.

Coding Agents Made Public Repos to Host 13,000 PR Screenshots. gh Couldn't Attach Images

Book: System Design Pocket Guide: Fundamentals The series: Pocket Guides for Developers — 8 short books on agents, RAG, prompts, observability, events, databases and system design — the whole series…

  • Coding agent created public repository with 13,000 screenshots
  • GitHub CLI couldn't attach images to PRs or issues
  • Fix introduced on September 1, 2026, enabling image uploads

More from Friday 16 October →