Fetch: Adjust FileSlicingCount runtime

Created on 12 Jun 2019  路  4Comments  路  Source: tonyofrancis/Fetch

Is it possible to set FileSlicingCount at runtime..? I want the user to set FileSlicingCount for specific download. And also the ability to set different chunk no for different downloading.
Same feature for DownloadConcurrentLimit. I want the user to set DownloadConcurrentLimit and also able to change DownloadConcurrentLimit at runtime.

help wanted

Most helpful comment

@maulik9898 The fileSlicingCount method is called for each download request when started. So you are able to set the slice count for any download request.

All 4 comments

@maulik9898 You would have to create a custom downloader and override method fun getFileSlicingCount(request: ServerRequest, contentLength: Long): Int?. Then set the custom downloader on the fetch configuration.

    @Override
    public void onCreate() {
        super.onCreate();
        final FetchConfiguration fetchConfiguration = new FetchConfiguration.Builder(this)
                .enableRetryOnNetworkGain(true)
                .setDownloadConcurrentLimit(3)
                .setHttpDownloader(new CustomParallelDownloader())
                .build();
        Fetch.Impl.setDefaultInstanceConfiguration(fetchConfiguration);
        RxFetch.Impl.setDefaultRxInstanceConfiguration(fetchConfiguration);
    }

    public static class CustomParallelDownloader extends OkHttpDownloader {

        public CustomParallelDownloader() {
            super(Downloader.FileDownloaderType.PARALLEL);
        }

        @Nullable
        @Override
        public Integer getFileSlicingCount(@NotNull Downloader.ServerRequest request, long contentLength) {
            //return new count here after checking request and content length
            return super.getFileSlicingCount(request, contentLength);
        }
    }

Note custom FileSlicingCount only works for Parallel Downloaders. Hope this helps.

Ok, so is there any way i can customise this fileslicing option for each and every new download request

@maulik9898 The fileSlicingCount method is called for each download request when started. So you are able to set the slice count for any download request.

Ohh i get it now. Thank you for this awesome library

Was this page helpful?
0 / 5 - 0 ratings

Related issues

DeevD picture DeevD  路  3Comments

jpvs0101 picture jpvs0101  路  5Comments

gbirk picture gbirk  路  5Comments

Moeinh77 picture Moeinh77  路  4Comments

cepero91 picture cepero91  路  4Comments