MCPcopy Create free account
hub / github.com/brimdata/super / Run

Method Run

cmd/super/dev/dig/slice/command.go:47–91  ·  view source on GitHub ↗
(args []string)

Source from the content-addressed store, hash-verified

45}
46
47func (c *Command) Run(args []string) error {
48 ctx, cleanup, err := c.Init(&c.outputFlags)
49 if err != nil {
50 return err
51 }
52 defer cleanup()
53 if len(args) != 2 {
54 return errors.New("super dev dig slice: requires a from:to specifier and a file")
55 }
56 uri, err := storage.ParseURI(args[1])
57 if err != nil {
58 return err
59 }
60 engine := storage.NewLocalEngine()
61 r, err := engine.Get(ctx, uri)
62 if err != nil {
63 return err
64 }
65 defer r.Close()
66 size, err := storage.Size(r)
67 if err != nil {
68 return err
69 }
70 from, to, err := parseSlice(args[0], size)
71 if err != nil {
72 return err
73 }
74 if from == to {
75 return errors.New("empty slice")
76 }
77 if from > to {
78 return errors.New("slice start cannot be after the end")
79 }
80 sctx := super.NewContext()
81 reader := bsupio.NewReader(sctx, io.NewSectionReader(r, int64(from), int64(to-from)))
82 defer reader.Close()
83 writer, err := c.outputFlags.Open(ctx, engine)
84 if err != nil {
85 return err
86 }
87 if err := vio.Copy(writer, sbuf.NewDematerializer(sctx, sbuf.NewPuller(reader))); err != nil {
88 return err
89 }
90 return writer.Close()
91}
92
93func parseSlice(s string, end int64) (int, int, error) {
94 vals := strings.Split(s, ":")

Callers

nothing calls this directly

Implementers 15

Displaypkg/display/display.go
Serverpkg/httpd/server.go
Commandcmd/gentoken/main.go
Commandcmd/super/dev/command.go
Commandcmd/super/dev/vector/command.go
Commandcmd/super/dev/vector/copy/command.go
Commandcmd/super/dev/vector/project/command.g
Commandcmd/super/dev/vector/search/command.go
Commandcmd/super/dev/dig/command.go
Commandcmd/super/dev/dig/frames/command.go
Commandcmd/super/dev/dig/slice/command.go
Commandcmd/super/dev/csup/command.go

Calls 15

CloseMethod · 0.95
ParseURIFunction · 0.92
NewLocalEngineFunction · 0.92
SizeFunction · 0.92
NewContextFunction · 0.92
NewReaderFunction · 0.92
CopyFunction · 0.92
NewDematerializerFunction · 0.92
NewPullerFunction · 0.92
parseSliceFunction · 0.85
NewMethod · 0.80
InitMethod · 0.65

Tested by

no test coverage detected