Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaurboy's M3Pro authored and Gaurboy's M3Pro committed Apr 28, 2024
1 parent 9b89f55 commit 7f576b3
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 70 deletions.
70 changes: 1 addition & 69 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ zbox is a command line interface (CLI) tool to understand the capabilities of Z
- [Repair](#repair)
- [Decrypt](#decrypt)
- [Sign data](#sign-data)
- [Streaming](#streaming)
- [How it works:](#how-it-works)
- [Usage](#usage)

- [Lock and Unlock Tokens](#lock-and-unlock-tokens)
- [Challenge pool information](#challenge-pool-information)
- [Create read pool](#create-read-pool)
Expand Down Expand Up @@ -1732,72 +1730,6 @@ Repair file completed, Total files repaired: 0
Signature : 9432ab2ee602062afaf48c4016b373a65db48a8546a81c09dead40e54966399e
```

---

#### Streaming

Video streaming with Zbox CLI can be implemented with players for different operating platforms(iOS, Android Mac).Zbox CLI does not have a player itself and use the the downloadFileByBlocks helper function to properly returns file-chunks with correct byte range.

![streaming-android](https://user-images.githubusercontent.com/65766301/120052635-ce373b00-c043-11eb-94a5-a9711078ee54.png)

##### How it works:

When the user starts the video player (ExoPlayer for Android or AVPlayer for iOS), A ZChainDataSource starts chunked download and requests chunks of video from the buffer(a Middleman between streaming player and Zbox).

After the arrival of the first chunk, the player starts requesting more chunks from the buffer, which requests the Zbox SDK. Zbox SDK, which is built using GO, makes use of the downloadFileByBlocks method to reliably download large files by chunking them into a sequence of parts that can be downloaded individually. Once the blocks are downloaded, they are read into input streams and added to the media source of the streaming player.

The task of downloading files and writing them to buffer using Zbox SDK happens constantly, and If players request random bits of video, they are delivered instantly by a buffer.

In a case, if the player didn't receive chunks (for example, it's still not downloaded), then the player switches to STALE state, and the video stream will pause. During the STALE state, a player tries to make multiple requests for chunks; if didn't receive a response, the video stream stops.

##### Usage

To understand how Zbox CLI provides downloading of files by blocks. Let's consider an allocation that has `audio. mp3 ` file stored on dStorage. Make sure the file has a large size(more than 64 kB(64000 bytes)) to download the file by blocks. The size and other attributes of the sample `audio. mp3` file can be viewed using

```
./zbox list --allocation $ALLOC --remotepath /myfiles
```

Response:

```
TYPE | NAME | PATH | SIZE | NUM BLOCKS |LOOKUP HASH | IS ENCRYPTED | DOWNLOADS PAYER
+------+-----------+--------------------+---------+------------+----------------
f | audio.mp3 | /myfiles/audio.mp3 | 5992396 | 92 | 3cea39505cc30fb9f6fc5c6045284188feb14eac8ff3a19577701c4f6d973239 | NO | owner
```
Here we can see the `audio.mp3` file of size (5993286) bytes having 92 blocks.If we want to download a certain number of blocks for the `audio.mp3` file we can use the `--endblock` or `--startblock` flag with `./zbox download` command. Other flags for download can be viewed using `./zbox download --help`

```
Flags:
-b, --blockspermarker int pass this option to download multiple blocks per marker (default 10)
-e, --endblock int pass this option to download till specific block number
-h, --help help for download
--localpath string Local path of file to download
--remotepath string Remote path to download
-s, --startblock int Pass this option to download from specific block number
```

For only downloading three blocks of `audio.mp3` file, we specify `--startblock` and`--endblock` with integer value of 1 and 3. `--blockspermarker` flag can also be specified to download multiple blocks at a time(default is 10).

Sample command for downloading till 3rd block of the `audio.mp3` file would be:

```
./zbox download --localpath /root --remotepath /myfiles/audio.mp3 --allocation $ALLOC --startblock 1 --endblock 3
```

Response:

```
393216 / 2996198 [====================>-----------------------------------------------------------------------------------------------------------------------------------------] 13.12% 1s
Status completed callback. Type = audio/mpeg. Name = audio.mp3
```

As we can see, the downloaded file size(393216) is less than the original(2996198), which means zbox has downloaded some blocks of the file.


### Lock and Unlock Tokens

#### Challenge pool information
Expand Down
67 changes: 66 additions & 1 deletion internal.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ Contents :
[Stream](#stream)
[Get MPT](#get-mpt)
[Rollback Allocation](#rollback-allocation)

[Streaming](#streaming)
- [How it works:](#how-it-works)
- [Usage](#usage)
#### Sync

`sync` command syncs all files from the local folder recursively to the remote.
Expand Down Expand Up @@ -146,3 +148,66 @@ Sample Response :
```sh
Rollback successful
```

#### Streaming

Video streaming with Zbox CLI can be implemented with players for different operating platforms(iOS, Android Mac).Zbox CLI does not have a player itself and use the the downloadFileByBlocks helper function to properly returns file-chunks with correct byte range.

![streaming-android](https://user-images.githubusercontent.com/65766301/120052635-ce373b00-c043-11eb-94a5-a9711078ee54.png)

##### How it works:

When the user starts the video player (ExoPlayer for Android or AVPlayer for iOS), A ZChainDataSource starts chunked download and requests chunks of video from the buffer(a Middleman between streaming player and Zbox).

After the arrival of the first chunk, the player starts requesting more chunks from the buffer, which requests the Zbox SDK. Zbox SDK, which is built using GO, makes use of the downloadFileByBlocks method to reliably download large files by chunking them into a sequence of parts that can be downloaded individually. Once the blocks are downloaded, they are read into input streams and added to the media source of the streaming player.

The task of downloading files and writing them to buffer using Zbox SDK happens constantly, and If players request random bits of video, they are delivered instantly by a buffer.

In a case, if the player didn't receive chunks (for example, it's still not downloaded), then the player switches to STALE state, and the video stream will pause. During the STALE state, a player tries to make multiple requests for chunks; if didn't receive a response, the video stream stops.

##### Usage

To understand how Zbox CLI provides downloading of files by blocks. Let's consider an allocation that has `audio. mp3 ` file stored on dStorage. Make sure the file has a large size(more than 64 kB(64000 bytes)) to download the file by blocks. The size and other attributes of the sample `audio. mp3` file can be viewed using

```
./zbox list --allocation $ALLOC --remotepath /myfiles
```

Response:

```
TYPE | NAME | PATH | SIZE | NUM BLOCKS |LOOKUP HASH | IS ENCRYPTED | DOWNLOADS PAYER
+------+-----------+--------------------+---------+------------+----------------
f | audio.mp3 | /myfiles/audio.mp3 | 5992396 | 92 | 3cea39505cc30fb9f6fc5c6045284188feb14eac8ff3a19577701c4f6d973239 | NO | owner
```
Here we can see the `audio.mp3` file of size (5993286) bytes having 92 blocks.If we want to download a certain number of blocks for the `audio.mp3` file we can use the `--endblock` or `--startblock` flag with `./zbox download` command. Other flags for download can be viewed using `./zbox download --help`

```
Flags:
-b, --blockspermarker int pass this option to download multiple blocks per marker (default 10)
-e, --endblock int pass this option to download till specific block number
-h, --help help for download
--localpath string Local path of file to download
--remotepath string Remote path to download
-s, --startblock int Pass this option to download from specific block number
```

For only downloading three blocks of `audio.mp3` file, we specify `--startblock` and`--endblock` with integer value of 1 and 3. `--blockspermarker` flag can also be specified to download multiple blocks at a time(default is 10).

Sample command for downloading till 3rd block of the `audio.mp3` file would be:

```
./zbox download --localpath /root --remotepath /myfiles/audio.mp3 --allocation $ALLOC --startblock 1 --endblock 3
```

Response:

```
393216 / 2996198 [====================>-----------------------------------------------------------------------------------------------------------------------------------------] 13.12% 1s
Status completed callback. Type = audio/mpeg. Name = audio.mp3
```

As we can see, the downloaded file size(393216) is less than the original(2996198), which means zbox has downloaded some blocks of the file.

0 comments on commit 7f576b3

Please sign in to comment.