image-size
semver
>=1.0.0postconditions6functions2last verified2026-04-17coverage score100%Postconditions — what we check
- imageSize · unsupported-formaterrorWhenImage format is unsupported or buffer is not a recognized image formatThrows
TypeError ('unsupported file type: ...' or 'disabled file type: ...')Required handlingCaller MUST wrap imageSize() in try-catch as it throws synchronously on unrecognized formats.costlowin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[1] - imageSize · corrupt-imageerrorWhenBuffer contains corrupt or truncated image dataThrows
TypeError ('Corrupt JPG', 'Invalid PNG', etc.)Required handlingCaller MUST wrap imageSize() in try-catch as it throws on corrupt image data.costlowin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[1] - imageSizeFromFile · file-not-founderrorWhenFile path does not exist or cannot be readThrows
Error (ENOENT, EACCES)Required handlingCaller MUST wrap imageSizeFromFile() in try-catch as it rejects on file system errors.costlowin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[2] - imageSizeFromFile · unsupported-formaterrorWhenFile is not a recognized image formatThrows
TypeError ('unsupported file type: ...')Required handlingCaller MUST wrap imageSizeFromFile() in try-catch as it rejects on unrecognized image formats.costlowin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[1] - imageSizeFromFile · empty-fileerrorWhenFile exists at the given path but has zero bytes (size <= 0)Throws
Error ('Empty file')Required handlingCaller MUST wrap imageSizeFromFile() in try-catch. An empty file rejects with Error('Empty file'), which is distinct from ENOENT (file missing) and from TypeError (unsupported format). Upload pipelines that check file existence before dimensions must also guard against the file being zero-length.costlowin prodimmediate exceptionusers seeservice unavailablevisibilityvisible - imageSizeFromFile · corrupt-image-asyncerrorWhenFile exists and is readable but contains corrupt or malformed image dataThrows
TypeError (e.g. 'Corrupt JPG, exceeded buffer limits', 'Invalid PNG', 'Invalid WebP', etc.)Required handlingCaller MUST wrap imageSizeFromFile() in try-catch. When the file contains corrupt image data, the async wrapper rejects with the same TypeError thrown by the synchronous imageSize() parser. Callers checking only for ENOENT/EACCES will miss format corruption errors from user-uploaded files.costlowin prodimmediate exceptionusers seeservice unavailablevisibilityvisible
Sources
Every postcondition cites at least one of these. Numbered to match the footnotes above.
Need a different package?
Request a profile