file.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. 'use strict'
  2. const path = require('path')
  3. /**
  4. * File object used for tracking files in `file-list.js`.
  5. */
  6. class File {
  7. constructor (path, mtime, doNotCache, type, isBinary, integrity) {
  8. // used for serving (processed path, eg some/file.coffee -> some/file.coffee.js)
  9. this.path = path
  10. // original absolute path, id of the file
  11. this.originalPath = path
  12. // where the content is stored (processed)
  13. this.contentPath = path
  14. // encodings format {[encodingType]: encodedContent}
  15. // example: {gzip: <Buffer 1f 8b 08...>}
  16. this.encodings = Object.create(null)
  17. this.mtime = mtime
  18. this.isUrl = false
  19. this.doNotCache = doNotCache === undefined ? false : doNotCache
  20. this.type = type
  21. // Tri state: null means probe file for binary.
  22. this.isBinary = isBinary === undefined ? null : isBinary
  23. this.integrity = integrity
  24. }
  25. /**
  26. * Detect type from the file extension.
  27. * @returns {string} detected file type or empty string
  28. */
  29. detectType () {
  30. return path.extname(this.path).slice(1)
  31. }
  32. toString () {
  33. return this.path
  34. }
  35. }
  36. module.exports = File