<commit_before>###
PDFImage - embeds images in PDF documents
By <NAME>
###

fs = require 'fs'
Data = require './data'
JPEG = require './image/jpeg'
PNG = require './image/png'

class PDFImage
  @open: (src, label) ->
    if Buffer.isBuffer(src)
      data = src
    else
      data = fs.readFileSync src
      return unless data
    
    if data[0] is 0xff and data[1] is 0xd8
      return new JPEG(data, label)
      
    else if data[0] is 0x89 and data.toString('ascii', 1, 4) is 'PNG'
      return new PNG(data, label)
      
    else
      throw new Error 'Unknown image format.'
          
module.exports = PDFImage<commit_msg>Add ability to add base64 URI images<commit_after>###
PDFImage - embeds images in PDF documents
By <NAME>
###

fs = require 'fs'
Data = require './data'
JPEG = require './image/jpeg'
PNG = require './image/png'

class PDFImage
  @open: (src, label) ->
    if Buffer.isBuffer(src)
      data = src
    else
      if src[0..4] is 'data:' and src.indexOf(';base64,') > -1
        base64String = src.split(';base64,')[1]
        data = new Buffer(base64String, 'base64')

      else
        data = fs.readFileSync src
        return unless data
    
    if data[0] is 0xff and data[1] is 0xd8
      return new JPEG(data, label)
      
    else if data[0] is 0x89 and data.toString('ascii', 1, 4) is 'PNG'
      return new PNG(data, label)
      
    else
      throw new Error 'Unknown image format.'
          
module.exports = PDFImage
{'fraction_non_alphanumeric': 0.11869031377899045, 'fraction_numerical': 0.02592087312414734, 'mean_word_length': 2.364678899082569, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4285755', 'n_tokens_mistral': 507, 'n_tokens_neox': 481, 'n_words': 165}