Diff

Differences From Artifact [1dda5424c0]:

To Artifact [675059111f]:


1
2
3

4
5
6
7
8
9
10
11
12

13
14
15
16
17
18
19
20




21
22
23
24
25
26
27
package main

import (

	iou "0dev.org/ioutil"
	predictor "0dev.org/predictor"
	"bufio"
	"fmt"
	"io"
	"os"
)

func main() {

	switch {
	case len(os.Args) == 1:
		os.Exit(compress(os.Stdout, os.Stdin))
	case len(os.Args) == 2 && os.Args[1] == "-d":
		os.Exit(decompress(os.Stdout, os.Stdin))
	default:
		fmt.Fprintln(os.Stdout, "Usage: pdc [-d]")
	}




}

// Compress the data from the given io.Reader and write it to the given io.Writer
// I/O is buffered for better performance
func compress(output io.Writer, input io.Reader) int {
	var (
		err        error



>


|






>


|

|



>
>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package main

import (
	pprof "0dev.org/debug/pprof"
	iou "0dev.org/ioutil"
	predictor "0dev.org/predictor"
	// "bufio"
	"fmt"
	"io"
	"os"
)

func main() {
	var code int
	switch {
	case len(os.Args) == 1:
		code = compress(os.Stdout, os.Stdin)
	case len(os.Args) == 2 && os.Args[1] == "-d":
		code = decompress(os.Stdout, os.Stdin)
	default:
		fmt.Fprintln(os.Stdout, "Usage: pdc [-d]")
	}

	pprof.Stop()

	os.Exit(code)
}

// Compress the data from the given io.Reader and write it to the given io.Writer
// I/O is buffered for better performance
func compress(output io.Writer, input io.Reader) int {
	var (
		err        error
54
55
56
57
58
59
60

61
62
63
64
65
66
67
68

// Decompress the data from the given io.Reader and write it to the given io.Writer
// I/O is buffered for better performance
func decompress(output io.Writer, input io.Reader) int {
	var (
		err          error
		buffer       io.Writer = iou.SizedWriter(output, 4096)

		decompressor io.Reader = predictor.Decompressor(bufio.NewReader(input))
	)

	_, err = io.Copy(buffer, decompressor)
	if err != nil {
		fmt.Fprintln(os.Stderr, "Error while decompressing.\n", err)
		return 1
	}







>
|







60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75

// Decompress the data from the given io.Reader and write it to the given io.Writer
// I/O is buffered for better performance
func decompress(output io.Writer, input io.Reader) int {
	var (
		err          error
		buffer       io.Writer = iou.SizedWriter(output, 4096)
		decompressor io.Reader = predictor.Decompressor(iou.SizedReader(input, 4096))
		//decompressor io.Reader = predictor.Decompressor(bufio.NewReader(input))
	)

	_, err = io.Copy(buffer, decompressor)
	if err != nil {
		fmt.Fprintln(os.Stderr, "Error while decompressing.\n", err)
		return 1
	}