File sync
This commit is contained in:
parent
b76502c034
commit
47c4c99b66
7 changed files with 174 additions and 19 deletions
|
|
@ -566,21 +566,32 @@ export class NodeStore {
|
|||
})
|
||||
}//}}}
|
||||
|
||||
async storeFile(file) {// {{{
|
||||
async storeFile(file, reader, progressCallback) {// {{{
|
||||
const metadata = new FileMetadata(file)
|
||||
let processedBytes = 0
|
||||
let stream
|
||||
|
||||
try {
|
||||
// Do potentially larger blocks.
|
||||
const BLOCKSIZE = 1048576
|
||||
const stream = file.stream()
|
||||
const reader = stream.getReader({ mode: 'byob' })
|
||||
let buffer = new Uint8Array(BLOCKSIZE)
|
||||
|
||||
// Files from server got through fetch() will bring its own
|
||||
// reader without going through a stream.
|
||||
if (!reader) {
|
||||
stream = file.stream()
|
||||
reader = stream.getReader({ mode: 'byob' })
|
||||
}
|
||||
|
||||
let seq = 0
|
||||
while (true) {
|
||||
const { done, value } = await reader.read(buffer)
|
||||
if (done) break
|
||||
|
||||
processedBytes += value.length
|
||||
if (progressCallback)
|
||||
progressCallback(processedBytes)
|
||||
|
||||
// Block is added as a file segment.
|
||||
await this.fileSegments.add({
|
||||
data: {
|
||||
|
|
@ -895,7 +906,6 @@ class FileNodesLinkStore extends SimpleNodeStore {
|
|||
|
||||
class FileMetadata {
|
||||
constructor(data) {// {{{
|
||||
console.log('md', data)
|
||||
this.UUID = data.UUID || uuidv7()
|
||||
this.uploaded = data.uploaded || 'only_on_device'
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue