fetch in chunks
v1.3.0
병렬 다운로드, 진행률 추적 및 중단 요청을 지원하여 대용량 파일을 청크로 가져오는 유틸리티입니다.
npm을 사용하여 패키지를 설치합니다.
npm 설치 청크 가져오기
'청크 가져오기'에서 fetchInChunks를 가져옵니다.
비동기 함수 fetchInChunks(url, 옵션 = {})
url
( string
): 다운로드할 파일의 URL입니다.
options
( object
, option): 추가 옵션이 포함된 개체입니다.
options.chunkSize
( number
, 기본값: 5 * 1024 * 1024
): 다운로드할 각 청크의 크기(바이트)입니다.
options.maxParallelRequests
( number
, 기본값: 1
): 병렬로 다운로드할 청크 수입니다.
options.progressCallback
( function
, option ): 다운로드된 바이트 수와 파일의 전체 크기와 함께 호출되는 콜백 함수입니다.
options.signal
( AbortSignal
, 선택 사항): 다운로드를 중단하는 데 사용할 수 있는 AbortSignal
개체입니다.
Promise<Blob>
: 다운로드한 파일이 포함된 Blob
으로 확인되는 Promise입니다.
'fetch-in-chunks'에서 fetchInChunks 가져오기; 비동기 함수 downloadFile() { {const blob = wait fetchInChunks('https://example.com/largefile.zip');return blob;을 시도하세요. } catch (error) {console.error('파일 가져오기 오류:', error); }}다운로드파일();
'fetch-in-chunks'에서 fetchInChunks 가져오기; 비동기 함수 downloadFileWithProgress() { {const blob = wait fetchInChunks('https://example.com/largefile.zip', { ProgressCallback: (다운로드됨, 총계) => {console.log(`다운로드됨 ${((다운로드됨 / 총계) * 100)을 시도하세요. .toFixed(2)}%`); },});반환; } catch (error) {console.error('파일 가져오기 오류:', error); }}downloadFileWithProgress();
AbortController
사용'fetch-in-chunks'에서 fetchInChunks 가져오기; 비동기 함수 downloadFileWithAbort() { const 컨트롤러 = 새로운 AbortController(); const 신호 = 컨트롤러.신호; {const blob = wait fetchInChunks('https://example.com/largefile.zip', { signal,});return blob;을 시도하세요. } catch (오류) {if (error.name === 'AbortError') { console.log('다운로드가 중단되었습니다');} else { console.error('파일 가져오기 오류:', error);} } // 언제든지 다운로드를 중단하려면 컨트롤러.중단();}
이 프로젝트는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 LICENSE
파일을 참조하세요.