1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | 'use strict';
|
11 |
|
12 | const Blob = require('Blob');
|
13 |
|
14 | const invariant = require('invariant');
|
15 |
|
16 | import type {BlobOptions} from 'BlobTypes';
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | class File extends Blob {
|
22 | |
23 |
|
24 |
|
25 | constructor(
|
26 | parts: Array<Blob | string>,
|
27 | name: string,
|
28 | options?: BlobOptions,
|
29 | ) {
|
30 | invariant(
|
31 | parts != null && name != null,
|
32 | 'Failed to construct `File`: Must pass both `parts` and `name` arguments.',
|
33 | );
|
34 |
|
35 | super(parts, options);
|
36 | this.data.name = name;
|
37 | }
|
38 |
|
39 | |
40 |
|
41 |
|
42 | get name(): string {
|
43 | invariant(this.data.name != null, 'Files must have a name set.');
|
44 | return this.data.name;
|
45 | }
|
46 |
|
47 | |
48 |
|
49 |
|
50 | get lastModified(): number {
|
51 | return this.data.lastModified || 0;
|
52 | }
|
53 | }
|
54 |
|
55 | module.exports = File;
|