MCPcopy Create free account
hub / github.com/creatale/node-dv / l_genDataString

Function l_genDataString

deps/leptonica/src/stringcode.c:698–734  ·  view source on GitHub ↗

! * \brief l_genDataString() * * \param[in] filein input file of serialized data * \param[in] ifunc index into set of functions in output file * \return encoded ascii data string, or NULL on error reading from file */

Source from the content-addressed store, hash-verified

696 * \return encoded ascii data string, or NULL on error reading from file
697 */
698static char *
699l_genDataString(const char *filein,
700 l_int32 ifunc)
701{
702char buf[80];
703char *cdata1, *cdata2, *cdata3;
704l_uint8 *data1, *data2;
705l_int32 csize1, csize2;
706size_t size1, size2;
707SARRAY *sa;
708
709 PROCNAME("l_genDataString");
710
711 if (!filein)
712 return (char *)ERROR_PTR("filein not defined", procName, NULL);
713
714 /* Read it in, gzip it, encode, and reformat. We gzip because some
715 * serialized data has a significant amount of ascii content. */
716 if ((data1 = l_binaryRead(filein, &size1)) == NULL)
717 return (char *)ERROR_PTR("bindata not returned", procName, NULL);
718 data2 = zlibCompress(data1, size1, &size2);
719 cdata1 = encodeBase64(data2, size2, &csize1);
720 cdata2 = reformatPacked64(cdata1, csize1, 4, 72, 1, &csize2);
721 LEPT_FREE(data1);
722 LEPT_FREE(data2);
723 LEPT_FREE(cdata1);
724
725 /* Prepend the string declaration signature and put it together */
726 sa = sarrayCreate(3);
727 snprintf(buf, sizeof(buf), "static const char *l_strdata_%d =\n", ifunc);
728 sarrayAddString(sa, buf, L_COPY);
729 sarrayAddString(sa, cdata2, L_INSERT);
730 sarrayAddString(sa, (char *)";\n", L_COPY);
731 cdata3 = sarrayToString(sa, 0);
732 sarrayDestroy(&sa);
733 return cdata3;
734}
735
736
737/*!

Callers 1

strcodeGenerateFunction · 0.85

Calls 8

l_binaryReadFunction · 0.85
encodeBase64Function · 0.85
reformatPacked64Function · 0.85
sarrayCreateFunction · 0.85
sarrayAddStringFunction · 0.85
sarrayToStringFunction · 0.85
sarrayDestroyFunction · 0.85
zlibCompressFunction · 0.70

Tested by

no test coverage detected