UNPKG

1.09 kBJavaScriptView Raw
1/**
2 * Copyright (c) Facebook, Inc. and its affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 *
7 * @flow
8 * @format
9 */
10'use strict';
11
12const Blob = require('Blob');
13
14const invariant = require('invariant');
15
16import type {BlobOptions} from 'BlobTypes';
17
18/**
19 * The File interface provides information about files.
20 */
21class File extends Blob {
22 /**
23 * Constructor for JS consumers.
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 * Name of the file.
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 * Last modified time of the file.
49 */
50 get lastModified(): number {
51 return this.data.lastModified || 0;
52 }
53}
54
55module.exports = File;