"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.LiveFontFileReader = exports.FontFileReaderId = exports.FontFileReader = void 0;
exports.makeFontFileReader = makeFontFileReader;
exports.read = void 0;

var T = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect-ts/core/Effect"));

var L = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect-ts/core/Effect/Layer"));

var S = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect-ts/core/Effect/Stream"));

var _Has = /*#__PURE__*/require("@effect-ts/core/Has");

var NS = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect-ts/node/Stream"));

var NodeJSFileSystem = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("fs"));

var _index = /*#__PURE__*/require("../FigletException/index.js");

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

// -----------------------------------------------------------------------------
// Model
// -----------------------------------------------------------------------------
const FontFileReaderId = /*#__PURE__*/Symbol();
exports.FontFileReaderId = FontFileReaderId;

function makeFontFileReader() {
  return (0, _Has.service)({
    read: (path, f) => {
      const buffer = S.mapError_(NS.streamFromReadable(() => NodeJSFileSystem.createReadStream(path)), e => new _index.FigletFileError({
        message: e.error.message
      }));
      return f(path, buffer);
    }
  });
}

const FontFileReader = /*#__PURE__*/(0, _Has.tag)(FontFileReaderId);
exports.FontFileReader = FontFileReader;
const LiveFontFileReader = /*#__PURE__*/L.fromFunction(FontFileReader)(makeFontFileReader);
exports.LiveFontFileReader = LiveFontFileReader;
const {
  read
} = /*#__PURE__*/T.deriveLifted(FontFileReader)(["read"], [], []);
exports.read = read;
//# sourceMappingURL=index.js.map