File: load_kmx_file.cpp

package info (click to toggle)
keyman 18.0.245-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 21,316 kB
  • sloc: python: 52,784; cpp: 21,278; sh: 7,633; ansic: 4,823; xml: 3,617; perl: 959; makefile: 139; javascript: 138
file content (34 lines) | stat: -rw-r--r-- 724 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <fstream>
#include <iostream>
#include <list>
#include <string>

#include "kmx_file.h"
#include "path.hpp"
#include "utfcodec.hpp"

namespace km::tests {

std::vector<uint8_t> load_kmx_file(km::core::path const& kb_path) {
  std::vector<uint8_t> data;
  std::ifstream file(static_cast<std::string>(kb_path), std::ios::binary | std::ios::ate);
  if (file.fail()) {
    return std::vector<uint8_t>();
  }
  const std::streamsize size = file.tellg();
  if (size >= KMX_MAX_ALLOWED_FILE_SIZE) {
    return std::vector<uint8_t>();
  }

  file.seekg(0, std::ios::beg);

  data.resize((size_t)size);
  if (!file.read((char*)data.data(), size)) {
    return std::vector<uint8_t>();
  }

  file.close();
  return data;
}

}