This repository was archived by the owner on Jan 24, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +52
-0
lines changed Expand file tree Collapse file tree 1 file changed +52
-0
lines changed Original file line number Diff line number Diff line change 9898}
9999const query = parseQuery(window.location.search); */
100100
101+ localforage . config ( { driver : localforage . INDEXEDDB } ) ;
102+ const chunkSize = 100 * 1024 * 1024 ;
103+ localforage . write = ( p , d ) => new Promise ( ( accept , reject ) => {
104+ console . log ( 'write' , p , d ) ;
105+ const _recurse = ( startIndex = 0 , index = 0 ) => {
106+ if ( startIndex < d . length ) {
107+ const slice = d . slice ( startIndex , startIndex + chunkSize ) ;
108+
109+ console . log ( 'set item' , p + '-' + index ) ;
110+ localforage . setItem ( p + '-' + index , slice , err => {
111+ if ( ! err ) {
112+ startIndex += slice . length ;
113+ index ++ ;
114+ _recurse ( startIndex , index ) ;
115+ } else {
116+ reject ( err ) ;
117+ }
118+ } ) ;
119+ } else {
120+ localforage . removeItem ( p + '-' + index , err => {
121+ if ( ! err ) {
122+ accept ( ) ;
123+ } else {
124+ reject ( err ) ;
125+ }
126+ } ) ;
127+ }
128+ } ;
129+ _recurse ( ) ;
130+ } ) ;
131+ localforage . read = p => new Promise ( ( accept , reject ) => {
132+ const result = [ ] ;
133+ const _recurse = ( index = 0 ) => {
134+ console . log ( 'get item' , p + '-' + index ) ;
135+ localforage . getItem ( p + '-' + index , ( err , data ) => {
136+ if ( ! err ) {
137+ if ( data ) {
138+ result . push ( data ) ;
139+
140+ index ++ ;
141+ _recurse ( index ) ;
142+ } else {
143+ accept ( result ) ;
144+ }
145+ } else {
146+ reject ( err ) ;
147+ }
148+ } ) ;
149+ } ;
150+ _recurse ( ) ;
151+ } ) ;
152+
101153// helpers
102154
103155const _getFrontOfCamera = ( ) => {
You can’t perform that action at this time.
0 commit comments