@@ -5,6 +5,7 @@ const { types } = require('util')
5
5
const { kState } = require ( './symbols' )
6
6
const { isBlobLike } = require ( './util' )
7
7
const { webidl } = require ( './webidl' )
8
+ const { parseMIMEType, serializeAMimeType } = require ( './dataURL' )
8
9
9
10
class File extends Blob {
10
11
constructor ( fileBits , fileName , options = { } ) {
@@ -34,13 +35,29 @@ class File extends Blob {
34
35
// outside the range U+0020 to U+007E, then set t to the empty string
35
36
// and return from these substeps.
36
37
// 2. Convert every character in t to ASCII lowercase.
37
- // Note: Blob handles both of these steps for us
38
+ let t = options . type
39
+ let d
38
40
39
- // 3. If the lastModified member is provided, let d be set to the
40
- // lastModified dictionary member. If it is not provided, set d to the
41
- // current date and time represented as the number of milliseconds since
42
- // the Unix Epoch (which is the equivalent of Date.now() [ECMA-262]).
43
- const d = options . lastModified
41
+ // eslint-disable-next-line no-labels
42
+ substep: {
43
+ if ( t ) {
44
+ t = parseMIMEType ( t )
45
+
46
+ if ( t === 'failure' ) {
47
+ t = ''
48
+ // eslint-disable-next-line no-labels
49
+ break substep
50
+ }
51
+
52
+ t = serializeAMimeType ( t ) . toLowerCase ( )
53
+ }
54
+
55
+ // 3. If the lastModified member is provided, let d be set to the
56
+ // lastModified dictionary member. If it is not provided, set d to the
57
+ // current date and time represented as the number of milliseconds since
58
+ // the Unix Epoch (which is the equivalent of Date.now() [ECMA-262]).
59
+ d = options . lastModified
60
+ }
44
61
45
62
// 4. Return a new File object F such that:
46
63
// F refers to the bytes byte sequence.
@@ -49,10 +66,11 @@ class File extends Blob {
49
66
// F.type is set to t.
50
67
// F.lastModified is set to d.
51
68
52
- super ( processBlobParts ( fileBits , options ) , { type : options . type } )
69
+ super ( processBlobParts ( fileBits , options ) , { type : t } )
53
70
this [ kState ] = {
54
71
name : n ,
55
- lastModified : d
72
+ lastModified : d ,
73
+ type : t
56
74
}
57
75
}
58
76
@@ -72,6 +90,14 @@ class File extends Blob {
72
90
return this [ kState ] . lastModified
73
91
}
74
92
93
+ get type ( ) {
94
+ if ( ! ( this instanceof File ) ) {
95
+ throw new TypeError ( 'Illegal invocation' )
96
+ }
97
+
98
+ return this [ kState ] . type
99
+ }
100
+
75
101
get [ Symbol . toStringTag ] ( ) {
76
102
return this . constructor . name
77
103
}
0 commit comments