LoginSignup
3
0

More than 5 years have passed since last update.

Node.jsでjpgの画像破損を判定する

Last updated at Posted at 2018-01-16

jpgの末尾が破損するという現象に出くわし、それを判定する必要があった。

jpgのバイナリのEOIは 0xFF 0xD9 なので、それをチェックすれば良い。

is_broken_jpg.js
"use strict";

module.exports = (buf) => {
  return !(
    buf[buf.length - 1] === 0xD9 &&
    buf[buf.length - 2] === 0xFF
  );
};
3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0