<commit_before>local Value = require "cosy.value"

local File = {}

function File.encode (filname, data)
  local file = io.open (filname, "w")
  file:write (Value.expression (data))
  file:close ()
end

function File.decode (filename)
  local file, err = io.open (filename, "r")
  if not file then
    error (err)
  end
  local data = file:read "*all"
  file:close ()
  return Value.decode (data)
end

return File<commit_msg>File.decode return nil, err instead of error(err).<commit_after>local Value = require "cosy.value"

local File = {}

function File.encode (filname, data)
  local file = io.open (filname, "w")
  file:write (Value.expression (data))
  file:close ()
end

function File.decode (filename)
  local file, err = io.open (filename, "r")
  if not file then
    return nil, err
  end
  local data = file:read "*all"
  file:close ()
  return Value.decode (data)
end

return File
{'fraction_non_alphanumeric': 0.12570145903479238, 'fraction_numerical': 0.0, 'mean_word_length': 3.847826086956522, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4516788', 'n_tokens_mistral': 299, 'n_tokens_neox': 298, 'n_words': 100}