Skip to content

[Replacement]: is-png #1035

Closed
Closed

Description

@outslept

Package to replace

is-png

Suggested replacement(s)

export const isPng = (b) =>
	b?.length >= 8
	&& new DataView(b.buffer, b.byteOffset, 8).getBigUint64(0) === 0x89504E470D0A1A0An;

regarding the bigint, see https://www.w3.org/TR/png/#5PNG-file-signature

Manifest type

micro-utility (tiny utility replaceable with native code or removal)

Rationale

simple canonical check. should be inlined

Availability

No response

Code example (optional)

Activity

  1. dreyfus92 commented on Aug 28, 2026

    @dreyfus92
    Member

    i'd swap the snippet for plain byte comparisons matching the is-gzip / is-deflate entries. the DataView+bigint version is correct on typed arrays (nice catch on byteOffset), but it throws on plain arrays where the package returns a boolean, allocates a DataView per call, and reads less obviously than eight hex compares. the boring version is also verbatim what the package ships

  2. added
    accepted
    on Aug 28, 2026
  3. gameroman commented on Aug 28, 2026

    @gameroman
    Contributor

    Yeah, looks like checking each byte is more efficient

    export const isPng = (b) =>
      b?.length >= 8 &&
      b[0] === 0x89 && b[1] === 0x50 && b[2] === 0x4e && b[3] === 0x47 &&
      b[4] === 0x0d && b[5] === 0x0a && b[6] === 0x1a && b[7] === 0x0a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions