<commit_before>#include <fstream>
#include <algorithm>
#include <iterator>

#include <node.h>
#include <nan.h>

using namespace v8;
/*Checks the PNG magic number, returns false if it doesn't correspond to a png
or it is too short*/
const std::string apng("acTL");
const std::string magicNum("\211PNG\r\n\032\n");
bool isPNG(std::ifstream &in)
{
  char buf[8];
  in.read(buf,8);
  return (buf==magicNum);
}
/*Checks if a file is png or apng.
Input: filename
Output: true if apng, false if png, -1if file isn't a png or apng and Undefined(and throws and exception) if there is an error.*/
NAN_METHOD(findapngCpp)
{
  NanScope();

  if(args.Length()<1){
    NanThrowTypeError("Wrong number of arguments");
    NanReturnUndefined();
  }
  if(!args[0]->IsString()){
    NanThrowTypeError("Wrong argument (should be a filename)");
    NanReturnUndefined();
  }
  std::ifstream in (*NanUtf8String(args[0]),std::ios_base::binary);
  if(!in.is_open()){
    NanThrowError("Can't open file");
    NanReturnUndefined();
  }

  if(!isPNG(in))
    NanReturnValue(NanNew<Number>(-1));

  std::istream_iterator<unsigned char> sta(in);
  std::istream_iterator<unsigned char> end;

  NanReturnValue(NanNew<Boolean>(std::search(sta,end,apng.begin(),apng.end())!=end));
}
void Init(Handle<Object> exports) {
  exports->Set(NanNew<String>("findapngCpp"),
  NanNew<FunctionTemplate>(findapngCpp)->GetFunction());
}
NODE_MODULE(findapng,Init)
<commit_msg>Fix magic number compare from findapng.cpp<commit_after>#include <fstream>
#include <algorithm>
#include <iterator>

#include <node.h>
#include <nan.h>

using namespace v8;

const std::string apng("acTL");
const std::string magicNum("\211PNG\r\n\032\n");
/*Checks the PNG magic number, returns false if it doesn't correspond to a png
or it is too short*/
bool isPNG(std::ifstream &in)
{
  char * buf=new char[8];
  in.read(buf,8);
  std::string str(buf,8);
  delete[] buf;
  return (str==magicNum);
}
/*Checks if a file is png or apng.
Input: filename
Output: true if apng, false if png, -1if file isn't a png or apng and Undefined(and throws and exception) if there is an error.*/
NAN_METHOD(findapngCpp)
{
  NanScope();

  if(args.Length()<1){
    NanThrowTypeError("Wrong number of arguments");
    NanReturnUndefined();
  }
  if(!args[0]->IsString()){
    NanThrowTypeError("Wrong argument (should be a filename)");
    NanReturnUndefined();
  }
  std::ifstream in (*NanUtf8String(args[0]),std::ios_base::binary);
  if(!in.is_open()){
    NanThrowError("Can't open file");
    NanReturnUndefined();
  }

  if(!isPNG(in))
    NanReturnValue(NanNew<Number>(-1));

  std::istream_iterator<unsigned char> sta(in);
  std::istream_iterator<unsigned char> end;

  NanReturnValue(NanNew<Boolean>(std::search(sta,end,apng.begin(),apng.end())!=end));
}
void Init(Handle<Object> exports) {
  exports->Set(NanNew<String>("findapngCpp"),
  NanNew<FunctionTemplate>(findapngCpp)->GetFunction());
}
NODE_MODULE(findapng,Init)

{'fraction_non_alphanumeric': 0.16152019002375298, 'fraction_numerical': 0.010519172039362062, 'mean_word_length': 5.464912280701754, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 33, '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': '2314496', 'n_tokens_mistral': 1092, 'n_tokens_neox': 1039, 'n_words': 248}