'Create a new file in the file store.
We delegate the actual file addition to our contained
implementations. Implementations can either implement the AddFile() method,
returning a file like object which will be written on, or directly support
the AddBlobToStore() method which can copy the VFSBlobImage efficiently.
Args:
fd: An AFF4 object open for read/write.
sync: Should the file be synced immediately.
external: If true, attempt to add files to stores defined as EXTERNAL.'

def AddFile(self, fd, sync=False, external=True):

    files_for_write = []
    for sub_store in self.GetChildrenByPriority(allow_external=external):
        new_file = sub_store.AddFile(fd, sync=sync)
        if new_file:
            files_for_write.append(new_file)
    fd.Seek(0)
    while files_for_write:
        data = fd.Read(self.CHUNK_SIZE)
        if (not data):
            break
        for child in files_for_write:
            child.Write(data)
    for child in files_for_write:
        child.Close(sync=sync)
