Last 12 weeks · 0 commits
4 of 6 standards met
Hello! We recently upgraded from -> and noticed a performance regression when calling on image buffers that are not XML. Large and images would previously get excuted around and now take upwards of . We would like to continue using the option for scenarios when the image buffer is an . In the meantime, we have had to downgrade to . This is what our function looks like. We take each image buffer and provide it to . If it returns a result, we return the content-type . If it doesn't, we then have infer it. Following the performance script from https://github.com/sindresorhus/is-svg/issues/42, I created another one to measure the performance of different file sizes for , , and . Here is the perf script, running on node 22.22.0 v5.1.0 results: v6.1.0 results: Should we be performing the custom detector suggestion from https://github.com/sindresorhus/file-type?tab=readme-ov-file#customdetectors to determine the file is XML, before trying to use ? If so, it would be great if this package explicitly states it should not be used until the content type is known to be XML. If this package should handle all image buffers in a timely manner, that would definitely be our preference, since it matches how we've used this package for the past many years! Thanks!
Fixes #46 Problem v6 introduced XmlTextDetector with fullScan by default. When checking non-SVG buffers (PNG/JPG), the detector scans the entire content — large images can be megabytes, causing ~600ms latency vs v5's ~0.1ms. Fix Add a cheap pre-check before the expensive XmlTextDetector: 1. Content must start with 2. First 512 bytes must contain , , or This rejects non-XML content immediately without running the full scan. Real SVG content passes through unchanged.
Extend , to which you can provide, in addition to an XML an . This may be convenient as the SVG may be encoded in multiple ways. Following text encodings automatically detected and supported: UTF8 without a preceding BOM field UTF8 with a preceding BOM field UTF16-LE without a preceding BOM field UTF16-BE without a preceding BOM field UTF16-LE with a preceding BOM field UTF16-BE with a preceding BOM field Build on top of #40, utilizing @file-type/xml, the XML detection plugin for file-type.
Repository: sindresorhus/is-svg. Description: Check if a string or buffer is SVG Stars: 142, Forks: 21. Primary language: JavaScript. Languages: JavaScript (97.3%), TypeScript (2.7%). License: MIT. Latest release: v6.1.0 (1y ago). Open PRs: 1, open issues: 1. Last activity: 6mo ago. Community health: 85%. Top contributors: sindresorhus, kevva, Borewit, BendingBender, SamVerschueren, urbanautomaton, steffenweber, StephanHoyer, kraftner, tprobinson and others.