<commit_before>package hmda.js.io

import scala.concurrent.{ Promise, Future }
import scala.scalajs.js
import scala.scalajs.js.Dynamic._

trait IO {
  val fs = global.require("fs")
  val options = js.Dynamic.literal(encoding = "UTF-8")

  def readFileSync(path: String): String = {
    fs.readFileSync(path, options).asInstanceOf[String]
  }

  def readFile(path: String): Future[String] = {
    val promise: Promise[String] = Promise()
    fs.readFile(path, options, { (err: js.Dynamic, data: String) =>
      if (err != null)
        promise.failure(new RuntimeException("could not read file"))
      else
        promise.success(data)
    })
    promise.future
  }
}<commit_msg>Add comments to JS IO<commit_after>package hmda.js.io

import scala.concurrent.{ Promise, Future }
import scala.scalajs.js
import scala.scalajs.js.Dynamic._

trait IO {
  val fs = global.require("fs")
  val options = js.Dynamic.literal(encoding = "UTF-8")

  // Wrapper around nodejs fs.readFileSync
  // https://nodejs.org/api/fs.html#fs_fs_readfilesync_file_options
  def readFileSync(path: String): String = {
    fs.readFileSync(path, options).asInstanceOf[String]
  }

  // Wrapper around nodejs fs.readFile
  // https://nodejs.org/api/fs.html#fs_fs_readfile_file_options_callback
  def readFile(path: String): Future[String] = {
    val promise: Promise[String] = Promise()
    fs.readFile(path, options, { (err: js.Dynamic, data: String) =>
      if (err != null)
        promise.failure(new RuntimeException("could not read file"))
      else
        promise.success(data)
    })
    promise.future
  }
}
{'fraction_non_alphanumeric': 0.1318267419962335, 'fraction_numerical': 0.0012554927809165098, 'mean_word_length': 3.5413105413105415, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 2, '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': '5404757', 'n_tokens_mistral': 529, 'n_tokens_neox': 531, 'n_words': 114}