17
17
18
18
import { isBase64Available } from '../platform/base64' ;
19
19
import { Code , FirestoreError } from '../util/error' ;
20
- import { ByteString } from '../util/byte_string' ;
21
20
import { Bytes } from '../../lite/src/api/bytes' ;
21
+ import { Compat } from '../compat/compat' ;
22
22
23
23
/** Helper function to assert Uint8Array is available at runtime. */
24
24
function assertUint8ArrayAvailable ( ) : void {
@@ -40,42 +40,30 @@ function assertBase64Available(): void {
40
40
}
41
41
}
42
42
43
- /**
44
- * Immutable class holding a blob (binary data).
45
- *
46
- * This class is directly exposed in the public API. It extends the Bytes class
47
- * of the firestore-exp API to support `instanceof Bytes` checks during user
48
- * data conversion.
49
- *
50
- * Note that while you can't hide the constructor in JavaScript code, we are
51
- * using the hack above to make sure no-one outside this module can call it.
52
- */
53
- export class Blob extends Bytes {
43
+ /** Immutable class holding a blob (binary data) */
44
+ export class Blob extends Compat < Bytes > {
54
45
static fromBase64String ( base64 : string ) : Blob {
55
46
assertBase64Available ( ) ;
56
- try {
57
- return new Blob ( ByteString . fromBase64String ( base64 ) ) ;
58
- } catch ( e ) {
59
- throw new FirestoreError (
60
- Code . INVALID_ARGUMENT ,
61
- 'Failed to construct Blob from Base64 string: ' + e
62
- ) ;
63
- }
47
+ return new Blob ( Bytes . fromBase64String ( base64 ) ) ;
64
48
}
65
49
66
50
static fromUint8Array ( array : Uint8Array ) : Blob {
67
51
assertUint8ArrayAvailable ( ) ;
68
- return new Blob ( ByteString . fromUint8Array ( array ) ) ;
52
+ return new Blob ( Bytes . fromUint8Array ( array ) ) ;
69
53
}
70
54
71
55
toBase64 ( ) : string {
72
56
assertBase64Available ( ) ;
73
- return super . toBase64 ( ) ;
57
+ return this . _delegate . toBase64 ( ) ;
74
58
}
75
59
76
60
toUint8Array ( ) : Uint8Array {
77
61
assertUint8ArrayAvailable ( ) ;
78
- return super . toUint8Array ( ) ;
62
+ return this . _delegate . toUint8Array ( ) ;
63
+ }
64
+
65
+ isEqual ( other : Blob ) : boolean {
66
+ return this . _delegate . isEqual ( other . _delegate ) ;
79
67
}
80
68
81
69
toString ( ) : string {
0 commit comments