2 netstring -- netstring format serialization library
3 Copyright (C) 2015-2020 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])
46 fd, err := os.Open(os.Args[2])
50 r := netstring.NewReader(fd)
59 fmt.Printf("%d\t%d\n", i, size)
63 if len(os.Args) != 4 {
66 chunk, err := strconv.Atoi(os.Args[3])
70 fd, err := os.Open(os.Args[2])
74 r := netstring.NewReader(fd)
75 for i := 0; i < chunk; i++ {
86 if _, err = io.Copy(os.Stdout, r); err != nil {
90 w := netstring.NewWriter(os.Stdout)
91 for i, fn := range os.Args[2:] {
92 fd, err := os.Open(fn)
100 size := uint64(fi.Size())
101 if _, err = w.WriteSize(size); err != nil {
104 if _, err = io.Copy(w, fd); err != nil {
107 fmt.Fprintf(os.Stderr, "%d\t%d\t%s\n", i, size, fn)