-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update sprint 1.12 (#1341) * wait for repair and increase numBlocks (#1338) * reorder wait group done (#1340) --------- Co-authored-by: Ebrahim Gomaa <ebrahim.gomaa.hg@gmail.com> * fix trailing whitespace (#1343) * Merge staging changes (#1346) * wait for repair and increase numBlocks (#1338) * reorder wait group done (#1340) * hotfix / remove hard coded prefix handling of encrypted upload (#1344) * remove hard coded prefix handling of encrypted upload * fix for other parts of the file --------- Co-authored-by: Hitenjain14 <57557631+Hitenjain14@users.noreply.github.com> Co-authored-by: Ebrahim Gomaa <ebrahim.gomaa.hg@gmail.com> * fix upload select (#1351) * fix workdir in mobile sdk (#1345) * fix mobile workdir * set multi op batch size * set option to download to disk in wasm (#1348) * fix panic in hash chan (#1352) * Fix merge conflict in sprint-1.12 (#1354) * wait for repair and increase numBlocks (#1338) * reorder wait group done (#1340) * hotfix / remove hard coded prefix handling of encrypted upload (#1344) * remove hard coded prefix handling of encrypted upload * fix for other parts of the file * increase batch size (#1349) --------- Co-authored-by: Ebrahim Gomaa <ebrahim.gomaa.hg@gmail.com> * repair in batches (#1347) * repair in batches * fix lint * fix unit test * fix batch size --------- Co-authored-by: Yury <yuderbasov@gmail.com> --------- Co-authored-by: Ebrahim Gomaa <ebrahim.gomaa.hg@gmail.com> Co-authored-by: peterlimg <54137706+peterlimg@users.noreply.github.com> Co-authored-by: Yury <yuderbasov@gmail.com>
- Loading branch information
1 parent
ea5f217
commit d5aa3ea
Showing
14 changed files
with
375 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
//go:build js && wasm | ||
// +build js,wasm | ||
|
||
package jsbridge | ||
|
||
import ( | ||
"errors" | ||
"io/fs" | ||
"sync" | ||
"syscall/js" | ||
) | ||
|
||
var jsFileWriterMutex sync.Mutex | ||
|
||
type FileWriter struct { | ||
writableStream js.Value | ||
} | ||
|
||
func (w *FileWriter) Write(p []byte) (int, error) { | ||
//js.Value doesn't work in parallel invoke | ||
jsFileWriterMutex.Lock() | ||
defer jsFileWriterMutex.Unlock() | ||
|
||
uint8Array := js.Global().Get("Uint8Array").New(len(p)) | ||
js.CopyBytesToJS(uint8Array, p) | ||
_, err := Await(w.writableStream.Call("write", uint8Array)) | ||
if len(err) > 0 && !err[0].IsNull() { | ||
return 0, errors.New("file_writer: " + err[0].String()) | ||
} | ||
return len(p), nil | ||
} | ||
|
||
func (w *FileWriter) Close() error { | ||
_, err := Await(w.writableStream.Call("close")) | ||
if len(err) > 0 && !err[0].IsNull() { | ||
return errors.New("file_writer: " + err[0].String()) | ||
} | ||
return nil | ||
} | ||
|
||
func (w *FileWriter) Read(p []byte) (int, error) { | ||
return 0, errors.New("file_writer: not supported") | ||
} | ||
|
||
func (w *FileWriter) Seek(offset int64, whence int) (int64, error) { | ||
return 0, nil | ||
} | ||
|
||
func (w *FileWriter) Sync() error { | ||
return nil | ||
} | ||
|
||
func (w *FileWriter) Stat() (fs.FileInfo, error) { | ||
return nil, nil | ||
} | ||
|
||
func NewFileWriter(filename string) (*FileWriter, error) { | ||
// writableStream := js.Global().Get("writableStream") | ||
// stream, err := Await(writableStream.Call("create", filename)) | ||
// if len(err) > 0 && !err[0].IsNull() { | ||
// return nil, errors.New("file_writer: " + err[0].String()) | ||
// } | ||
// return &FileWriter{ | ||
// writableStream: stream[0], | ||
// }, nil | ||
if !js.Global().Get("window").Get("showSaveFilePicker").Truthy() || !js.Global().Get("window").Get("WritableStream").Truthy() { | ||
return nil, errors.New("file_writer: not supported") | ||
} | ||
|
||
showSaveFilePicker := js.Global().Get("window").Get("showSaveFilePicker") | ||
//create options with suggested name | ||
options := js.Global().Get("Object").New() | ||
options.Set("suggestedName", filename) | ||
|
||
//request a file handle | ||
fileHandle, err := Await(showSaveFilePicker.Invoke(options)) | ||
if len(err) > 0 && !err[0].IsNull() { | ||
return nil, errors.New("file_writer: " + err[0].String()) | ||
} | ||
//create a writable stream | ||
writableStream, err := Await(fileHandle[0].Call("createWritable")) | ||
if len(err) > 0 && !err[0].IsNull() { | ||
return nil, errors.New("file_writer: " + err[0].String()) | ||
} | ||
return &FileWriter{ | ||
writableStream: writableStream[0], | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.