copy-file.ais

execute(input)
  storage = service "storage_documents"
  root = storage.root()
  source = root.get(input.sourcePath)
  if source == null
    fail NotFound "Source file not found"
  end
  if not source.isFile()
    fail InvalidInput "Source is not a file"
  end
  if root.get(input.destinationPath) != null
    fail Conflict "Destination already exists"
  end
  destination = root.newFile(input.destinationPath)
  reader = source.openRead()
  writer = null
  copied = 0
  try
    writer = destination.openWrite()
    chunk = reader.read(65536)
    while chunk != null
      writer.write(chunk)
      copied = copied + Bytes.size(chunk)
      chunk = reader.read(65536)
    end
  finally
    try
      if writer != null
        writer.close()
      end
    finally
      reader.close()
    end
  end
  // File creation is an external effect, not a database transaction.
  return { copiedBytes: copied }
end
All examples

Search AISDL

Search the paper, references and examples.