Skip to content

Commit

Permalink
sync stream
Browse files Browse the repository at this point in the history
  • Loading branch information
Hitenjain14 committed Jan 10, 2024
1 parent f8e9172 commit f10d139
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 40 deletions.
23 changes: 6 additions & 17 deletions wasmsdk/demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,10 @@ <h2>please download zcn.wasm from https://github.com/0chain/gosdk/releases/lates
}

const getWallet = () => {
const clientID = get('clientId').value
const publicKey = get('publicKey').value
const privateKey = get('privateKey').value
const mnemonic = get('mnemonic').value
const clientID = "df52981c5474ddde9e4710bc1c2037cf5d573c4c9e53fee5807a25e4eba5d2a4"
const publicKey = "149722c817f8216a823ea276beff5633bb864ecdbba2e911306f5893d5f4b80e7b99e5452b0801fbd72b3ff3c8beb1cd6dd7da07b1eaf53bd367e8ee01e1c41d"
const privateKey = "3bdd53941219d8b0744732f86dd944fbc63414610b9c5dba8340c4eb11e5421f"
const mnemonic = "course planet divide fitness sauce busy bunker that buddy chief title whale long yellow glass galaxy estate bid swarm ride keep decrease model fog"
return {
clientID, publicKey, privateKey, mnemonic
}
Expand Down Expand Up @@ -211,7 +211,7 @@ <h2>please download zcn.wasm from https://github.com/0chain/gosdk/releases/lates

let network = query.get('network')
if (!network || network == 'undefined') {
network = "test.zus.network"
network = "demo.zus.network"
}

const blockWorker = 'https://' + network + '/dns';
Expand Down Expand Up @@ -457,7 +457,6 @@ <h2>please download zcn.wasm from https://github.com/0chain/gosdk/releases/lates
allocationId: allocationId,
remotePath: `/${file.name}`,
file: file,
thumbnailBytes: await readBytes(file),//only for demo, don't upload original file as thumbnail in production
encrypt: false,
webstreaming: false,
isUpdate: false,
Expand Down Expand Up @@ -868,17 +867,7 @@ <h2>please download zcn.wasm from https://github.com/0chain/gosdk/releases/lates
})

onClick('btnSetWalletInfo', async () => {
const jsonWallet = {
"client_id": "30764bcba73216b67c36b05a17b4dd076bfdc5bb0ed84856f27622188c377269",
"client_key": "1f495df9605a4479a7dd6e5c7a78caf9f9d54e3a40f62a3dd68ed377115fe614d8acf0c238025f67a85163b9fbf31d10fbbb4a551d1cf00119897edf18b1841c",
"keys": [
{ "public_key": "1f495df9605a4479a7dd6e5c7a78caf9f9d54e3a40f62a3dd68ed377115fe614d8acf0c238025f67a85163b9fbf31d10fbbb4a551d1cf00119897edf18b1841c", "private_key": "41729ed8d82f782646d2d30b9719acfd236842b9b6e47fee12b7bdbd05b35122" }
],
"mnemonics": "glare mistake gun joke bid spare across diagram wrap cube swear cactus cave repeat you brave few best wild lion pitch pole original wasp",
"version": "1.0",
"date_created": "1662534022",
"nonce": 0
}
const jsonWallet = {"client_id":"df52981c5474ddde9e4710bc1c2037cf5d573c4c9e53fee5807a25e4eba5d2a4","client_key":"149722c817f8216a823ea276beff5633bb864ecdbba2e911306f5893d5f4b80e7b99e5452b0801fbd72b3ff3c8beb1cd6dd7da07b1eaf53bd367e8ee01e1c41d","keys":[{"public_key":"149722c817f8216a823ea276beff5633bb864ecdbba2e911306f5893d5f4b80e7b99e5452b0801fbd72b3ff3c8beb1cd6dd7da07b1eaf53bd367e8ee01e1c41d","private_key":"3bdd53941219d8b0744732f86dd944fbc63414610b9c5dba8340c4eb11e5421f"}],"mnemonics":"course planet divide fitness sauce busy bunker that buddy chief title whale long yellow glass galaxy estate bid swarm ride keep decrease model fog","version":"1.0","date_created":"2024-01-10T13:57:57+05:30","nonce":0}
const splitKeyWallet = true
try {
const jsonWalletString = JSON.stringify(jsonWallet);
Expand Down
39 changes: 16 additions & 23 deletions wasmsdk/jsbridge/file_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,18 @@ func (w *FileWriter) Write(p []byte) (int, error) {
w.uint8Array = js.Global().Get("Uint8Array").New(w.bufLen)
}
js.CopyBytesToJS(w.uint8Array, p)
_, err := Await(w.writableStream.Call("write", w.uint8Array))
if len(err) > 0 && !err[0].IsNull() {
return 0, errors.New("file_writer: " + err[0].String())
}
w.writableStream.Call("write", w.uint8Array)
w.written++
w.totalWritten += len(p)
if w.written >= 3 {
w.Close()
w.written = 0
return len(p), w.SetNewWriter(w.totalWritten)
w.writableStream.Call("flush")
}
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())
}
w.writableStream.Call("close")
return nil
}

Expand Down Expand Up @@ -86,7 +79,7 @@ func NewFileWriter(filename string) (*FileWriter, error) {
return nil, errors.New("file_writer: " + err[0].String())
}
//create a writable stream
writableStream, err := Await(fileHandle[0].Call("createWritable"))
writableStream, err := Await(fileHandle[0].Call("createSyncAccessHandle"))
if len(err) > 0 && !err[0].IsNull() {
return nil, errors.New("file_writer: " + err[0].String())
}
Expand All @@ -96,15 +89,15 @@ func NewFileWriter(filename string) (*FileWriter, error) {
}, nil
}

func (w *FileWriter) SetNewWriter(offset int) error {
writableStream, err := Await(w.fileHandle.Call("createWritable"))
if len(err) > 0 && !err[0].IsNull() {
return errors.New("file_writer: " + err[0].String())
}
w.writableStream = writableStream[0]
_, err = Await(w.writableStream.Call("seek", offset))
if len(err) > 0 && !err[0].IsNull() {
return errors.New("file_writer: " + err[0].String())
}
return nil
}
// func (w *FileWriter) SetNewWriter(offset int) error {
// writableStream, err := Await(w.fileHandle.Call("createWritable"))
// if len(err) > 0 && !err[0].IsNull() {
// return errors.New("file_writer: " + err[0].String())
// }
// w.writableStream = writableStream[0]
// _, err = Await(w.writableStream.Call("seek", offset))
// if len(err) > 0 && !err[0].IsNull() {
// return errors.New("file_writer: " + err[0].String())
// }
// return nil
// }

0 comments on commit f10d139

Please sign in to comment.