File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed
Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -426,7 +426,19 @@ export class HuggingFaceAPI {
426426 async commitDirectFile ( filePath , file , commitMessage ) {
427427 const url = `${ this . baseURL } /api/datasets/${ this . repo } /commit/main` ;
428428
429- const content = btoa ( String . fromCharCode ( ...new Uint8Array ( await file . arrayBuffer ( ) ) ) ) ;
429+ const bytes = new Uint8Array ( await file . arrayBuffer ( ) ) ;
430+ // 分块转换,避免大文件导致 Maximum call stack size exceeded
431+ const chunkSize = 4096 ;
432+ const parts = [ ] ;
433+ for ( let i = 0 ; i < bytes . length ; i += chunkSize ) {
434+ const chunk = bytes . subarray ( i , Math . min ( i + chunkSize , bytes . length ) ) ;
435+ let s = '' ;
436+ for ( let j = 0 ; j < chunk . length ; j ++ ) {
437+ s += String . fromCharCode ( chunk [ j ] ) ;
438+ }
439+ parts . push ( s ) ;
440+ }
441+ const content = btoa ( parts . join ( '' ) ) ;
430442
431443 const body = [
432444 JSON . stringify ( {
You can’t perform that action at this time.
0 commit comments