 
 # Public: Represents an individual file in the editor.
 #
-# The entry point for this class is in two locations:
-# * {TextBuffer}, which associates text contents with a file
-# * {Directory}, which associcates the children of a directory as files
+# This class shouldn't be created directly, instead you should create a 
+# {Directory} and access the {File} objects that it creates.
 module.exports =
 class File
   _.extend @prototype, EventEmitter

      @cachedContents = null
      @trigger "removed"

  subscribeToNativeChangeEvents: ->
    @watchSubscription = pathWatcher.watch @path, (eventType, path) =>
      @handleNativeChangeEvent(eventType, path)

  unsubscribeFromNativeChangeEvents: ->
    if @watchSubscription
      @watchSubscription.close()

  path: null
  cachedContents: null

  # Private: Creates a new file.
  #
  # * path:
  #   A String representing the file path
  # * symlink:
  #   A Boolean indicating if the path is a symlink (default: false)
  constructor: (@path, @symlink=false) ->
    try
      if fs.statSync(@path).isDirectorySync()
        throw new Error("#{@path} is a directory")

  # Private: Sets the path for the file.
  setPath: (@path) ->

  # Public: Returns the path for the file.
  getPath: -> @path

  # Public: Return the filename without any directory information.
  getBaseName: ->
    path.basename(@path)

  # Public: Overwrites the file with the given String.
  write: (text) ->
    previouslyExisted = @exists()
    @cachedContents = text
    fsUtils.writeSync(@getPath(), text)
    @subscribeToNativeChangeEvents() if not previouslyExisted and @subscriptionCount() > 0

  # Public: Reads the contents of the file.
  #
  # * flushCache:
  #   A Boolean indicating whether to require a direct read or if a cached
  #   copy is acceptable.
  #
  # Returns a String.
  read: (flushCache)->
    if not @exists()
      @cachedContents = null
