file.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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) {
  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. }
  24. /**
  25. * Detect type from the file extension.
  26. * @returns {string} detected file type or empty string
  27. */
  28. detectType () {
  29. return path.extname(this.path).slice(1)
  30. }
  31. toString () {
  32. return this.path
  33. }
  34. }
  35. module.exports = File