Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uint8Array #11

Open
manzil-infinity180 opened this issue Sep 15, 2024 · 0 comments
Open

uint8Array #11

manzil-infinity180 opened this issue Sep 15, 2024 · 0 comments
Assignees

Comments

@manzil-infinity180
Copy link
Owner

 ```
     const sendFileUsingOtherWay = async (file) => {
                  const chunkSize = 16 * 1024;
                  let offset = 0;
          
                  socketDetail.emit('fileOptions', {
                      'filetype': file.type,
                      'filename': file.name
                  });
          
                  const sendBuffer = async (buffer) => {
                      fileTransferChannel.send(new Uint8Array(buffer));
                  }
                  const sendNextChunkFile = async () => {
                      const slice = file.slice(offset,offset+chunkSize);
                      const buffer = await slice.arrayBuffer();
                      await sendBuffer(buffer);
          
                      offset += buffer.byteLength;
          
                      const progress = Math.round((offset / file.size) * 100);
                      console.log(`Progress: ${progress}%`);
          
                      if(offset < file.size){
                          await sendNextChunkFile();
                      }else{
                          console.log('File transfer complete');
                          setSelectedFile(null);
                      }
                  }
          
                  await sendNextChunkFile();
            }
@manzil-infinity180 manzil-infinity180 self-assigned this Oct 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant