async getPath()

in src/io/directory.ts [47:66]


  async getPath(_path: string) {
    if (!Object.prototype.hasOwnProperty.call(this.files, _path)) {
      throw new Error(`Path "${_path}" does not exist in this dir.`);
    }

    if (this.files[_path].size > this.maxSizeBytes) {
      throw new Error(`File "${_path}" is too large. Aborting`);
    }

    const absoluteDirPath = path.resolve(this.path);
    const filePath = path.resolve(path.join(absoluteDirPath, _path));

    // This is belt and braces. Should never happen that a file was in
    // the files object and yet doesn't meet these requirements.
    if (!filePath.startsWith(absoluteDirPath) || _path.startsWith('/')) {
      throw new Error(`Path argument must be relative to ${this.path}`);
    }

    return filePath;
  }