{"size": 1104, "ext": "js", "max_stars_repo_path": "src/disassemble.js", "max_stars_repo_name": "ThisTNTSquid/file-disassembler", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/disassemble.js", "max_issues_repo_name": "ThisTNTSquid/file-disassembler", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/disassemble.js", "max_forks_repo_name": "ThisTNTSquid/file-disassembler", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 25.6744186047, "max_line_length": 85, "alphanum_fraction": 0.5987318841}
const path = require("path");
const fs = require("fs");
const uuid = require("uuid/v4");
const dir = "./output";

let ind = [];

let main = file => {
  let content = fs.readFileSync(file, "utf-8");

  if (!fs.existsSync(dir)) {
    fs.mkdirSync(dir);
  }

  content = content.split("");

  console.time("exec");
  console.log("Disassembler started")
  for (let i = 0; i < content.length; i++) {
    let hex = uuid();
    let hexHead = hex.charAt(0) + hex.charAt(1);
    if (!fs.existsSync(path.join(dir, hexHead))) {
      fs.mkdirSync(path.join(dir, hexHead));
    }
    ind.push(hex);
    fs.writeFile(path.join(dir, hexHead, hex), content[i], err => {
      console.log(`Broke ${i + 1} of ${content.length} -> ${dir}/${hexHead}/${hex}`);
    });
  }
  console.timeEnd("exec");
  fs.writeFile(path.join(dir, "index.json"), JSON.stringify(ind), err => {
    if (err) {
      console.log("something went wrong while writing index");
    } else {
      console.log("Index successfully written in output");
    }
  });
  console.log("Process completed")
};

module.exports = main;
// console.log(content);
