Example #1
0
//	Attempts to xml.Unmarshal() all files in the "infiles" sub-directory of the specified directory path into the interface{} structure returned by the specified constructor.
//	For each such input file, then attempts to xml.MarshalIndent() said structure back into a new output XML file with the same name, in the "outfiles" sub-directory of the specified directory path.
func TestViaRemarshal(dirPath string, makeEmptyDoc func() interface{}) {
	var dirPathInFiles = filepath.Join(dirPath, "infiles")
	var dirPathOutFiles = filepath.Join(dirPath, "outfiles")
	var loadXmlDocFile = func(filename string) bool {
		log.Printf("Loading %s", filename)
		doc, dataOrig := makeEmptyDoc(), ufs.ReadBinaryFile(filename, true)
		err := xml.Unmarshal(dataOrig, doc)
		if err != nil {
			panic(err)
		}
		if OnDocLoaded != nil {
			OnDocLoaded(doc)
		}
		outFileName := filepath.Join(dirPathOutFiles, filepath.Base(filename))
		log.Printf("Writing %s", outFileName)
		dataFaks, err := xml.MarshalIndent(doc, "", "\t")
		if err != nil {
			panic(err)
		}
		ufs.WriteTextFile(outFileName, strings.Trim(string(dataFaks), " \r\n\t"))
		log.Printf("Verifying...")
		if errs := verifyDocs(dataOrig, dataFaks); len(errs) > 0 {
			for _, err = range errs {
				log.Printf("%v", err)
			}
		}
		return true
	}
	if errs := ufs.NewDirWalker(false, nil, loadXmlDocFile).Walk(dirPathInFiles); len(errs) > 0 {
		panic(errs[0])
	}
}
Example #2
0
func main() {
	ugo.MaxProcs()
	ufs.NewDirWalker(false, nil, func(fullPath string) bool {
		blobs = append(blobs, ufs.ReadBinaryFile(fullPath, true))
		return true
	}).Walk(dirPath)

	testComp("flate1", func(w io.Writer) (wc io.WriteCloser) {
		var err error
		if wc, err = flate.NewWriter(w, 1); err != nil {
			panic(err)
		}
		return
	}, flate.NewReader)
	testComp("flate9", func(w io.Writer) (wc io.WriteCloser) {
		var err error
		if wc, err = flate.NewWriter(w, 9); err != nil {
			panic(err)
		}
		return
	}, flate.NewReader)
	testComp("lzw\t", func(w io.Writer) io.WriteCloser {
		return lzw.NewWriter(w, lzw.MSB, 8)
	}, func(r io.Reader) io.ReadCloser {
		return lzw.NewReader(r, lzw.MSB, 8)
	})
	testComp("zlib", func(w io.Writer) io.WriteCloser {
		return zlib.NewWriter(w)
	}, func(r io.Reader) (rc io.ReadCloser) {
		var err error
		if rc, err = zlib.NewReader(r); err != nil {
			panic(err)
		}
		return
	})
	testComp("gzip", func(w io.Writer) io.WriteCloser {
		return gzip.NewWriter(w)
	}, func(r io.Reader) (rc io.ReadCloser) {
		var err error
		if rc, err = gzip.NewReader(r); err != nil {
			panic(err)
		}
		return
	})
	printStats("PACK:", packStats)
	printStats("UNPACK:", unpackStats)
}
Example #3
0
func makeEmbeds(srcDirPath string) {
	defer wait.Done()
	filePath := filepath.Join(srcDirPath, "splash.png")
	var buf ustr.Buffer
	buf.Writeln("\t//\tEmbedded binary from %s", filePath)
	if raw := ufs.ReadBinaryFile(filePath, true); len(raw) > 0 {
		if strings.HasSuffix(filePath, ".png") {
			if src, _, err := image.Decode(bytes.NewReader(raw)); err == nil {
				dst, _ := ugfx.CreateLike(src, false)
				ugfx.PreprocessImage(src, dst, true, true, true)
				w := new(bytes.Buffer)
				png.Encode(w, dst)
				raw = w.Bytes()
			} else {
				panic(err)
			}
		}
		if len(raw) > 0 {
			buf.Writeln("\tCore.Libs.Images.SplashScreen.InitFrom.RawData = %#v", raw)
		}
	}
	newSrc.embeds = buf.String()
}