File tree 1 file changed +21
-9
lines changed
1 file changed +21
-9
lines changed Original file line number Diff line number Diff line change @@ -42,6 +42,13 @@ function writeImage(filename, data) {
42
42
} ) ;
43
43
}
44
44
45
+ function writeDup ( filename , data ) {
46
+ let dupstr = ( "0000" + dup ) . slice ( - 5 ) ;
47
+ console . log ( `Write ${ filename } .${ dupstr } ` ) ;
48
+ writeImage ( `${ filename } .${ dupstr } ` , data ) ;
49
+ dup ++ ;
50
+ }
51
+
45
52
async function fetcher ( ) {
46
53
let gotOptions = {
47
54
retries : 0 ,
@@ -59,17 +66,22 @@ async function fetcher() {
59
66
}
60
67
61
68
try {
62
- start = Date . now ( ) ;
63
- const response = await got ( url , gotOptions ) ;
64
- // FIXME should probably ping pong rather than copy
65
- lastImage = response . body . slice ( 0 ) ;
66
- filename = start ;
67
- dup = 0 ;
68
- writeImage ( filename , response . body ) ;
69
+ if ( start ) {
70
+ writeDup ( start , lastImage ) ;
71
+ } else {
72
+ start = Date . now ( ) ;
73
+ const response = await got ( url , gotOptions ) ;
74
+ // FIXME should probably ping pong rather than copy
75
+ lastImage = response . body . slice ( 0 ) ;
76
+ filename = start ;
77
+ start = 0 ;
78
+ dup = 0 ;
79
+ writeImage ( filename , response . body ) ;
80
+ }
69
81
} catch {
82
+ let dupname = start ;
83
+ writeDup ( start , lastImage ) ;
70
84
start = 0 ;
71
- writeImage ( filename + "." + dup , lastImage ) ;
72
- dup ++ ;
73
85
}
74
86
75
87
if ( count ++ > 1000000 ) {
You can’t perform that action at this time.
0 commit comments