@@ -1897,6 +1897,108 @@ var CUSTOM_TESTS = [
1897
1897
} ) ;
1898
1898
}
1899
1899
} ,
1900
+ {
1901
+ description : "Pause and resume works for chunks with NetworkStreamer" ,
1902
+ disabled : ! XHR_ENABLED ,
1903
+ timeout : 30000 ,
1904
+ expected : [ "Etiam a dolor vitae est vestibulum" , "84" , "DEF" ] ,
1905
+ run : function ( callback ) {
1906
+ var chunkNum = 0 ;
1907
+ Papa . parse ( BASE_PATH + "verylong-sample.csv" , {
1908
+ download : true ,
1909
+ chunkSize : 1000 ,
1910
+ chunk : function ( results , parser ) {
1911
+ chunkNum ++ ;
1912
+ parser . pause ( ) ;
1913
+
1914
+ if ( chunkNum === 2 ) {
1915
+ callback ( results . data [ 0 ] ) ;
1916
+ return ;
1917
+ }
1918
+
1919
+ parser . resume ( ) ;
1920
+ } ,
1921
+ complete : function ( ) {
1922
+ callback ( new Error ( "Should have found matched row before parsing whole file" ) ) ;
1923
+ }
1924
+ } ) ;
1925
+ }
1926
+ } ,
1927
+ {
1928
+ description : "Pause and resume works for chunks with FileStreamer" ,
1929
+ disabled : ! XHR_ENABLED ,
1930
+ timeout : 30000 ,
1931
+ expected : [ "Etiam a dolor vitae est vestibulum" , "84" , "DEF" ] ,
1932
+ run : function ( callback ) {
1933
+ var chunkNum = 0 ;
1934
+ var xhr = new XMLHttpRequest ( ) ;
1935
+ xhr . onload = function ( ) {
1936
+ Papa . parse ( new File ( [ xhr . responseText ] , './verylong-sample.csv' ) , {
1937
+ chunkSize : 1000 ,
1938
+ chunk : function ( results , parser ) {
1939
+ chunkNum ++ ;
1940
+ parser . pause ( ) ;
1941
+
1942
+ if ( chunkNum === 2 ) {
1943
+ callback ( results . data [ 0 ] ) ;
1944
+ return ;
1945
+ }
1946
+
1947
+ parser . resume ( ) ;
1948
+ } ,
1949
+ complete : function ( ) {
1950
+ callback ( new Error ( "Should have found matched row before parsing whole file" ) ) ;
1951
+ }
1952
+ } ) ;
1953
+ } ;
1954
+
1955
+ xhr . open ( "GET" , BASE_PATH + "verylong-sample.csv" ) ;
1956
+ try {
1957
+ xhr . send ( ) ;
1958
+ } catch ( err ) {
1959
+ callback ( err ) ;
1960
+ return ;
1961
+ }
1962
+ }
1963
+ } ,
1964
+ {
1965
+ description : "Pause and resume works for chunks with StringStreamer" ,
1966
+ disabled : ! XHR_ENABLED ,
1967
+ timeout : 30000 ,
1968
+ // Test also with string as byte size may be diferent
1969
+ expected : [ "Etiam a dolor vitae est vestibulum" , "84" , "DEF" ] ,
1970
+ run : function ( callback ) {
1971
+ var chunkNum = 0 ;
1972
+ var xhr = new XMLHttpRequest ( ) ;
1973
+ xhr . onload = function ( ) {
1974
+ Papa . parse ( xhr . responseText , {
1975
+ chunkSize : 1000 ,
1976
+ chunk : function ( results , parser ) {
1977
+ chunkNum ++ ;
1978
+ parser . pause ( ) ;
1979
+
1980
+ if ( chunkNum === 2 ) {
1981
+ callback ( results . data [ 0 ] ) ;
1982
+ return ;
1983
+ }
1984
+
1985
+ parser . resume ( ) ;
1986
+ } ,
1987
+ complete : function ( ) {
1988
+ callback ( new Error ( "Should have found matched row before parsing whole file" ) ) ;
1989
+ }
1990
+ } ) ;
1991
+ } ;
1992
+
1993
+ xhr . open ( "GET" , BASE_PATH + "verylong-sample.csv" ) ;
1994
+ try {
1995
+ xhr . send ( ) ;
1996
+ } catch ( err ) {
1997
+ callback ( err ) ;
1998
+ return ;
1999
+ }
2000
+ }
2001
+ } ,
1900
2002
{
1901
2003
description : "Complete is called with all results if neither step nor chunk is defined" ,
1902
2004
expected : [ [ 'A' , 'b' , 'c' ] , [ 'd' , 'E' , 'f' ] , [ 'G' , 'h' , 'i' ] ] ,
0 commit comments