2 netstring -- netstring format serialization library
3 Copyright (C) 2015-2022 Sergey Matveev <stargrave@stargrave.org>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, version 3 of the License.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
27 "go.cypherpunks.ru/netstring/v2"
31 fmt.Fprintf(os.Stderr, "ns -- Work with netstring encoded files\n\n")
32 fmt.Fprintf(os.Stderr, "Usage: %s list FILE\n", os.Args[0])
33 fmt.Fprintf(os.Stderr, " %s read FILE CHUNK > data\n", os.Args[0])
34 fmt.Fprintf(os.Stderr, " %s write FILE ... > data\n", os.Args[0])
35 fmt.Fprintf(os.Stderr, "FILE can be \"-\" for reading from stdin\n")
39 func fileRead(path string) io.Reader {
43 fd, err := os.Open(path)
58 r := netstring.NewReader(fileRead(os.Args[2]))
67 fmt.Printf("%d\t%d\n", i, size)
71 if len(os.Args) != 4 {
74 chunk, err := strconv.Atoi(os.Args[3])
78 r := netstring.NewReader(fileRead(os.Args[2]))
79 for i := 0; i < chunk; i++ {
90 if _, err = io.Copy(os.Stdout, r); err != nil {
94 w := netstring.NewWriter(os.Stdout)
95 for i, fn := range os.Args[2:] {
96 fd, err := os.Open(fn)
104 size := uint64(fi.Size())
105 if _, err = w.WriteSize(size); err != nil {
108 if _, err = io.Copy(w, fd); err != nil {
111 fmt.Fprintf(os.Stderr, "%d\t%d\t%s\n", i, size, fn)