11
11
#import " ReactNativeBlobUtilFS.h"
12
12
#import " ReactNativeBlobUtilConst.h"
13
13
#import " ReactNativeBlobUtilFileTransformer.h"
14
- @ import AssetsLibrary;
14
+ # import < AssetsLibrary/AssetsLibrary.h >
15
15
16
16
#import < CommonCrypto/CommonDigest.h>
17
17
@@ -58,9 +58,9 @@ - (id)initWithCallback:(RCTResponseSenderBlock)callback {
58
58
return self;
59
59
}
60
60
61
- - (id )initWithBridgeRef : (RCTBridge *)bridgeRef {
61
+ - (id )initWithEventDispatcherRef : (RCTEventDispatcher *)eventDispatcherRef {
62
62
self = [super init ];
63
- self.bridge = bridgeRef ;
63
+ self.eventDispatcher = eventDispatcherRef ;
64
64
return self;
65
65
}
66
66
@@ -69,7 +69,7 @@ + (NSArray *) getFileStreams {
69
69
70
70
if (fileStreams == nil )
71
71
fileStreams = [[NSMutableDictionary alloc ] init ];
72
- return fileStreams;
72
+ return fileStreams. allValues ;
73
73
}
74
74
75
75
+(void ) setFileStream : (ReactNativeBlobUtilFS *) instance withId : (NSString *) uuid {
@@ -160,11 +160,11 @@ + (void) readStream:(NSString *)uri
160
160
bufferSize : (int )bufferSize
161
161
tick : (int )tick
162
162
streamId : (NSString *)streamId
163
- bridgeRef : (RCTBridge *)bridgeRef
163
+ eventDispatcherRef : (RCTEventDispatcher *)eventDispatcherRef
164
164
{
165
165
[[self class ] getPathFromUri: uri completionHandler: ^(NSString *path, ALAssetRepresentation *asset) {
166
166
167
- __block RCTEventDispatcher * event = bridgeRef. eventDispatcher ;
167
+ __block RCTEventDispatcher * event = eventDispatcherRef ;
168
168
__block int read = 0 ;
169
169
__block int backoff = tick *1000 ;
170
170
__block int chunkSize = bufferSize;
@@ -508,15 +508,16 @@ + (void) readFile:(NSString *)path
508
508
__block Byte * buffer;
509
509
if (asset != nil )
510
510
{
511
- buffer = malloc (asset.size );
511
+ int size = asset.size ;
512
+ buffer = (Byte *)malloc (size);
512
513
[asset getBytes: buffer fromOffset: 0 length: asset.size error: &err];
513
514
if (err != nil )
514
515
{
515
516
onComplete (nil , @" EUNSPECIFIED" , [err description ]);
516
517
free (buffer);
517
518
return ;
518
519
}
519
- fileContent = [NSData dataWithBytes: buffer length: asset. size];
520
+ fileContent = [NSData dataWithBytes: buffer length: size];
520
521
free (buffer);
521
522
}
522
523
else
@@ -555,21 +556,25 @@ + (void) readFile:(NSString *)path
555
556
if ([[encoding lowercaseString ] isEqualToString: @" utf8" ])
556
557
{
557
558
NSString * utf8 = [[NSString alloc ] initWithData: fileContent encoding: NSUTF8StringEncoding];
558
- if (utf8 == nil )
559
- onComplete ([[NSString alloc ] initWithData: fileContent encoding: NSISOLatin1StringEncoding], nil , nil );
560
- else
561
- onComplete (utf8, nil , nil );
559
+ if (utf8 == nil ) {
560
+ NSString * latin1 = [[NSString alloc ] initWithData: fileContent encoding: NSISOLatin1StringEncoding];
561
+ NSData * latin1Data = [latin1 dataUsingEncoding: NSISOLatin1StringEncoding];
562
+ onComplete (latin1Data, nil , nil );
563
+ } else {
564
+ onComplete (fileContent, nil , nil );
565
+ }
562
566
}
563
567
else if ([[encoding lowercaseString ] isEqualToString: @" base64" ]) {
564
- onComplete ([fileContent base64EncodedStringWithOptions: 0 ], nil , nil );
568
+ NSString * base64String = [fileContent base64EncodedStringWithOptions: 0 ];
569
+ onComplete ([[NSData alloc ] initWithBase64EncodedString: base64String options: 0 ], nil , nil );
565
570
}
566
571
else if ([[encoding lowercaseString ] isEqualToString: @" ascii" ]) {
567
572
NSMutableArray * resultArray = [NSMutableArray array ];
568
- char * bytes = [fileContent bytes ];
573
+ char * bytes = ( char *) [fileContent bytes ];
569
574
for (int i=0 ;i<[fileContent length ];i++) {
570
575
[resultArray addObject: [NSNumber numberWithChar: bytes[i]]];
571
576
}
572
- onComplete (resultArray, nil , nil );
577
+ onComplete (( NSData *) resultArray, nil , nil );
573
578
}
574
579
}
575
580
else
@@ -690,11 +695,11 @@ + (NSDictionary *) stat:(NSString *) path error:(NSError **) error {
690
695
if ([fm fileExistsAtPath: path isDirectory: &isDir] == NO ) {
691
696
return nil ;
692
697
}
693
- NSDictionary * info = [fm attributesOfItemAtPath: path error: & error];
694
- NSString * size = [NSString stringWithFormat: @" %d " , [info fileSize ]];
698
+ NSDictionary * info = [fm attributesOfItemAtPath: path error: error];
699
+ NSString * size = [NSString stringWithFormat: @" %llu " , [info fileSize ]];
695
700
NSString * filename = [path lastPathComponent ];
696
701
NSDate * lastModified;
697
- [[NSURL fileURLWithPath: path] getResourceValue: &lastModified forKey: NSURLContentModificationDateKey error: & error];
702
+ [[NSURL fileURLWithPath: path] getResourceValue: &lastModified forKey: NSURLContentModificationDateKey error: error];
698
703
return @{
699
704
@" size" : size,
700
705
@" filename" : filename,
@@ -759,7 +764,7 @@ - (void)writeEncodeChunk:(NSString *) chunk {
759
764
NSUInteger left = [decodedData length ];
760
765
NSUInteger nwr = 0 ;
761
766
do {
762
- nwr = [self .outStream write: [decodedData bytes ] maxLength: left];
767
+ nwr = [self .outStream write: ( const uint8_t *) [decodedData bytes ] maxLength: left];
763
768
if (-1 == nwr) break ;
764
769
left -= nwr;
765
770
} while (left > 0 );
@@ -773,7 +778,7 @@ - (void)write:(NSData *) chunk {
773
778
NSUInteger left = [chunk length ];
774
779
NSUInteger nwr = 0 ;
775
780
do {
776
- nwr = [self .outStream write: [chunk bytes ] maxLength: left];
781
+ nwr = [self .outStream write: ( const uint8_t *) [chunk bytes ] maxLength: left];
777
782
if (-1 == nwr) break ;
778
783
left -= nwr;
779
784
} while (left > 0 );
@@ -826,7 +831,7 @@ + (void)slice:(NSString *)path
826
831
long max = MIN (size, [end longValue ]);
827
832
828
833
if (![fm fileExistsAtPath: dest]) {
829
- if (![fm createFileAtPath: dest contents: @" " attributes: nil ]) {
834
+ if (![fm createFileAtPath: dest contents: [ NSData new ] attributes: nil ]) {
830
835
return reject (@" ENOENT" , [NSString stringWithFormat: @" File '%@ ' does not exist and could not be created" , path], nil );
831
836
}
832
837
}
@@ -842,15 +847,15 @@ + (void)slice:(NSString *)path
842
847
}
843
848
else
844
849
{
845
- NSLog (@" read chunk %lu " , 10240 );
850
+ NSLog (@" read chunk %d " , 10240 );
846
851
chunkSize = 10240 ;
847
852
chunk = [handle readDataOfLength: 10240 ];
848
853
}
849
854
if ([chunk length ] <= 0 )
850
855
break ;
851
856
long remain = expected - read;
852
857
853
- [os write: [chunk bytes ] maxLength: chunkSize];
858
+ [os write: ( const uint8_t *) [chunk bytes ] maxLength: chunkSize];
854
859
read += [chunk length ];
855
860
}
856
861
[handle closeFile ];
@@ -868,19 +873,20 @@ + (void)slice:(NSString *)path
868
873
long max = MIN (size, [end longValue ]);
869
874
870
875
while (read < expected) {
871
- uint8_t * chunk[10240 ];
876
+ uint8_t chunk[10240 ];
877
+ uint8_t * pointerToChunk = &chunk[0 ];
872
878
long chunkSize = 0 ;
873
879
if ([start longValue ] + read + 10240 > max)
874
880
{
875
881
NSLog (@" read chunk %lu " , max - read - [start longValue ]);
876
882
chunkSize = max - read - [start longValue ];
877
- chunkRead = [asset getBytes: chunk fromOffset: [start longValue ] + read length: chunkSize error: nil ];
883
+ chunkRead = [asset getBytes: pointerToChunk fromOffset: [start longValue ] + read length: chunkSize error: nil ];
878
884
}
879
885
else
880
886
{
881
887
NSLog (@" read chunk %lu " , 10240 );
882
888
chunkSize = 10240 ;
883
- chunkRead = [asset getBytes: chunk fromOffset: [start longValue ] + read length: chunkSize error: nil ];
889
+ chunkRead = [asset getBytes: pointerToChunk fromOffset: [start longValue ] + read length: chunkSize error: nil ];
884
890
}
885
891
if ( chunkRead <= 0 )
886
892
break ;
0 commit comments