Skip to content

Commit 33f1fbc

Browse files
committed
fix(plugin): update function signatures
1 parent fbc4d6d commit 33f1fbc

File tree

3 files changed

+25
-27
lines changed

3 files changed

+25
-27
lines changed

internal/plugin/host.go

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -117,60 +117,59 @@ func (host *DriverHost) Log(level plugin_warp.LogLevel, message string) {
117117
}
118118
}
119119

120-
// load-config: func() -> result<string, string>;
120+
// load-config: func(driver: u32) -> result<list<u8>, string>;
121121
func (host *DriverHost) LoadConfig(driverHandle uint32) witgo.Result[[]byte, string] {
122122
driver, ok := host.driver.Get(driverHandle)
123123
if !ok || driver == nil {
124-
return witgo.Err[[]byte, string]("host.driver is null, loading timing too early")
124+
return witgo.Err[[]byte]("host.driver is null, loading timing too early")
125125
}
126126
return witgo.Ok[[]byte, string](driver.additional.Bytes())
127127
}
128128

129-
// save-config: func(config: string) -> result<_, string>;
129+
// save-config: func(driver: u32, config: list<u8>) -> result<_, string>;
130130
func (host *DriverHost) SaveConfig(driverHandle uint32, config []byte) witgo.Result[witgo.Unit, string] {
131131
driver, ok := host.driver.Get(driverHandle)
132132
if !ok || driver == nil {
133-
return witgo.Err[witgo.Unit, string]("host.driver is null, loading timing too early")
133+
return witgo.Err[witgo.Unit]("host.driver is null, loading timing too early")
134134
}
135135

136136
driver.additional.SetBytes(config)
137137
op.MustSaveDriverStorage(driver)
138138
return witgo.Ok[witgo.Unit, string](witgo.Unit{})
139139
}
140140

141-
// stream: func() -> result<output-stream, string>;
142-
func (host *DriverHost) Stream(this plugin_warp.UploadReadable) witgo.Result[io_v0_2.OutputStream, string] {
141+
// streams: func() -> result<input-stream, string>;
142+
func (host *DriverHost) Stream(this plugin_warp.UploadReadable) witgo.Result[io_v0_2.InputStream, string] {
143143
upload, ok := host.uploads.Get(this)
144144
if !ok {
145-
return witgo.Err[io_v0_2.OutputStream, string]("UploadReadable::Stream: ErrorCodeBadDescriptor")
145+
return witgo.Err[io_v0_2.InputStream]("UploadReadable::Stream: ErrorCodeBadDescriptor")
146146
}
147-
148-
if !upload.StreamConsume {
149-
upload.StreamConsume = true
150-
streamHandle := host.StreamManager().Add(manager_io.NewAsyncStreamForReader(upload))
151-
return witgo.Ok[io_v0_2.OutputStream, string](streamHandle)
147+
if upload.StreamConsume {
148+
return witgo.Err[io_v0_2.InputStream]("UploadReadable::Stream: StreamConsume")
152149
}
153-
return witgo.Err[io_v0_2.OutputStream, string]("UploadReadable::Stream: StreamConsume")
150+
151+
upload.StreamConsume = true
152+
streamHandle := host.StreamManager().Add(&manager_io.Stream{Reader: upload, Seeker: upload.GetFile()})
153+
return witgo.Ok[io_v0_2.InputStream, string](streamHandle)
154154
}
155155

156-
// stream-peek: func(offset: u64, len: u64) -> result<output-stream, string>;
157-
func (host *DriverHost) StreamPeek(this plugin_warp.UploadReadable, offset uint64, len uint64) witgo.Result[io_v0_2.OutputStream, string] {
156+
// peek: func(offset: u64, len: u64) -> result<input-stream, string>;
157+
func (host *DriverHost) StreamPeek(this plugin_warp.UploadReadable, offset uint64, len uint64) witgo.Result[io_v0_2.InputStream, string] {
158158
upload, ok := host.uploads.Get(this)
159159
if !ok {
160-
return witgo.Err[io_v0_2.OutputStream]("UploadReadable::StreamPeek: ErrorCodeBadDescriptor")
160+
return witgo.Err[io_v0_2.InputStream]("UploadReadable::StreamPeek: ErrorCodeBadDescriptor")
161161
}
162-
163162
if upload.StreamConsume {
164-
return witgo.Err[io_v0_2.OutputStream]("UploadReadable::StreamPeek: StreamConsume")
163+
return witgo.Err[io_v0_2.InputStream]("UploadReadable::StreamPeek: StreamConsume")
165164
}
166165

167166
peekReader, err := upload.RangeRead(http_range.Range{Start: int64(offset), Length: int64(len)})
168167
if err != nil {
169-
return witgo.Err[io_v0_2.OutputStream](err.Error())
168+
return witgo.Err[io_v0_2.InputStream](err.Error())
170169
}
171-
172-
streamHandle := host.StreamManager().Add(&manager_io.Stream{Reader: peekReader})
173-
return witgo.Ok[io_v0_2.OutputStream, string](streamHandle)
170+
seeker, _ := peekReader.(io.Seeker)
171+
streamHandle := host.StreamManager().Add(&manager_io.Stream{Reader: peekReader, Seeker: seeker})
172+
return witgo.Ok[io_v0_2.InputStream, string](streamHandle)
174173
}
175174

176175
// chunks: func(len: u32) -> result<u32, string>;
@@ -185,6 +184,7 @@ func (host *DriverHost) Chunks(this plugin_warp.UploadReadable, len uint32) witg
185184
if upload.SectionReader != nil {
186185
return witgo.Err[uint32]("UploadReadable::Chunks: Already exist chunk reader")
187186
}
187+
188188
ss, err := stream.NewStreamSectionReader(upload, int(len), &upload.UpdateProgress)
189189
if err != nil {
190190
return witgo.Err[uint32](err.Error())
@@ -233,7 +233,7 @@ func (host *DriverHost) ChunkReset(this plugin_warp.UploadReadable, chunk io_v0_
233233
return witgo.Ok[witgo.Unit, string](witgo.Unit{})
234234
}
235235

236-
// get-hasher: func(hashs: list<hash-alg>) -> result<hash-info, string>;
236+
// get-hasher: func(hashs: list<hash-alg>) -> result<list<hash-info>, string>;
237237
func (host *DriverHost) GetHasher(this plugin_warp.UploadReadable, hashs []plugin_warp.HashAlg) witgo.Result[[]plugin_warp.HashInfo, string] {
238238
upload, ok := host.uploads.Get(this)
239239
if !ok {

internal/plugin/manager_driver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func (h *DriverPluginHandler) Register(ctx context.Context, plugin *PluginInfo)
3232
err = op.RegisterDriver(func() driver.Driver {
3333
driver, err := plugin.driver.NewWasmDriver()
3434
if err != nil {
35-
log.Errorf("deferred load driver plugin err: %w", err)
35+
log.Errorf("deferred load driver plugin err: %v", err)
3636
}
3737
return driver
3838
})

internal/plugin/warp/upload.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ type UploadReadableManager = witgo.ResourceManager[*UploadReadableType]
3535
type UploadReadable = uint32
3636

3737
func NewUploadManager() *UploadReadableManager {
38-
return witgo.NewResourceManager[*UploadReadableType](func(resource *UploadReadableType) {
39-
resource.FileStreamer.Close()
40-
})
38+
return witgo.NewResourceManager[*UploadReadableType](nil)
4139
}
4240

4341
func HashTypeConvert(typ *utils.HashType) HashAlg {

0 commit comments

Comments
 (0)