parseOpt method

MobiRawml parseOpt(
  1. bool parseToc,
  2. bool parseDict,
  3. bool reconstruct
)

Implementation

MobiRawml parseOpt(bool parseToc, bool parseDict, bool reconstruct) {
  final maxLen = getMaxTextSize(this);
  if (maxLen == mobiNotSet) {
    throw MobiInvalidDataException("Text Length Too Long");
  }

  int length = maxLen;
  MobiRawml rawml = MobiRawml();
  final rawRawml = RawMlUtils.getRawml(this, length);
  if (existsFdst(this)) {
    if (mobiHeader?.fdstSectionCount != null &&
        mobiHeader!.fdstSectionCount! > 1) {
      rawml.fdst = DartMobiReader.readFdst(this);
    }
  }

  RawMlUtils.reconstructFlow(rawml, rawRawml, length);
  RawMlUtils.reconstructResources(this, rawml);
  final offset = getKf8Offset(this);
  if (existsSkelIndx(this) && existsFragIndx(this)) {
    final indxRecordNumber = mobiHeader!.skeletonIndex! + offset;
    MobiIndx skelMeta = MobiIndx();
    RawMlUtils.parseIndex(this, skelMeta, indxRecordNumber);
    rawml.skel = skelMeta;
  }
  if (existsFragIndx(this)) {
    MobiIndx fragMeta = MobiIndx();
    final indxRecordNumber = mobiHeader!.fragmentIndex! + offset;
    RawMlUtils.parseIndex(this, fragMeta, indxRecordNumber);
    rawml.frag = fragMeta;
  }
  if (parseToc) {
    if (existsGuideIndx(this)) {
      MobiIndx guideMeta = MobiIndx();
      final indxRecordNumber = mobiHeader!.guideIndex! + offset;
      RawMlUtils.parseIndex(this, guideMeta, indxRecordNumber);
      rawml.guide = guideMeta;
    }
    if (existsNcx(this)) {
      MobiIndx ncxMeta = MobiIndx();
      final indxRecordNumber = mobiHeader!.ncxIndex! + offset;
      RawMlUtils.parseIndex(this, ncxMeta, indxRecordNumber);
      rawml.ncx = ncxMeta;
    }
  }

  if (parseDict && isDictionary(this)) {
    MobiIndx orthData = MobiIndx();
    final indxRecordNumber = mobiHeader!.orthographicIndex! + offset;
    RawMlUtils.parseIndex(this, orthData, indxRecordNumber);
    rawml.orth = orthData;
    if (existsInfl(this)) {
      MobiIndx inflData = MobiIndx();
      final indxRecordNumber = mobiHeader!.inflectionIndex! + offset;
      RawMlUtils.parseIndex(this, inflData, indxRecordNumber);
      rawml.infl = inflData;
    }
  }
  RawMlUtils.reconstructParts(rawml);
  if (reconstruct) {
    RawMlUtils.reconstructLinks(rawml);
    if (mobiIsKf8(this)) {}
  }
  if (getEncoding(this) == MobiEncoding.CP1252) {
    // convert to utf8
  }
  return rawml;
}