File.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. const Blob = require('./Blob');
  12. const invariant = require('invariant');
  13. import type {BlobOptions} from './BlobTypes';
  14. /**
  15. * The File interface provides information about files.
  16. */
  17. class File extends Blob {
  18. /**
  19. * Constructor for JS consumers.
  20. */
  21. constructor(
  22. parts: Array<Blob | string>,
  23. name: string,
  24. options?: BlobOptions,
  25. ) {
  26. invariant(
  27. parts != null && name != null,
  28. 'Failed to construct `File`: Must pass both `parts` and `name` arguments.',
  29. );
  30. super(parts, options);
  31. this.data.name = name;
  32. }
  33. /**
  34. * Name of the file.
  35. */
  36. get name(): string {
  37. invariant(this.data.name != null, 'Files must have a name set.');
  38. return this.data.name;
  39. }
  40. /*
  41. * Last modified time of the file.
  42. */
  43. get lastModified(): number {
  44. return this.data.lastModified || 0;
  45. }
  46. }
  47. module.exports = File;