elemental.html.FileReaderSync Maven / Gradle / Ivy
/*
* Copyright 2012 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package elemental.html;
import elemental.events.*;
import elemental.util.*;
import elemental.dom.*;
import elemental.html.*;
import elemental.css.*;
import elemental.stylesheets.*;
import java.util.Date;
/**
* The FileReaderSync
interface allows to read File
or Blob
objects in a synchronous way.
This interface is only available in workers as it enables synchronous I/O that could potentially block.
*/
public interface FileReaderSync {
/**
* This method reads the contents of the specified Blob
or File
. When the read operation is finished, it returns an ArrayBuffer
representing the file's data. If an error happened during the read, the adequate exception is sent.
Parameters
blob
- The DOM
Blob
or File
to read into the ArrayBuffer
.
Return value
An ArrayBuffer
representing the file's data.
Exceptions
The following exceptions can be raised by this method:
NotFoundError
- is raised when the resource represented by the DOM
Blob
or File
cannot be found, e. g. because it has been erased. SecurityError
- is raised when one of the following problematic situation is detected:
- the resource has been modified by a third party;
- two many read are performed simultaneously;
- the file pointed by the resource is unsafe for a use from the Web (like it is a system file).
NotReadableError
- is raised when the resource cannot be read due to a permission problem, like a concurrent lock.
EncodingError
- is raised when the resource is a data URL and exceed the limit length defined by each browser.
*/
ArrayBuffer readAsArrayBuffer(Blob blob);
/**
* This method reads the contents of the specified Blob
, which may be a File
. When the read operation is finished, it returns a DOMString
containing the raw binary data from the file. If an error happened during the read, the adequate exception is sent.
Note : This method is deprecated and readAsArrayBuffer()
should be used instead.
Return value
A
DOMString
containing the raw binary data from the resource
Exceptions
The following exceptions can be raised by this method:
NotFoundError
- is raised when the resource represented by the DOM
Blob
or File
cannot be found, e. g. because it has been erased. SecurityError
- is raised when one of the following problematic situation is detected:
- the resource has been modified by a third party;
- two many read are performed simultaneously;
- the file pointed by the resource is unsafe for a use from the Web (like it is a system file).
NotReadableError
- is raised when the resource cannot be read due to a permission problem, like a concurrent lock.
EncodingError
- is raised when the resource is a data URL and exceed the limit length defined by each browser.
*/
String readAsBinaryString(Blob blob);
/**
* This method reads the contents of the specified Blob
or File
. When the read operation is finished, it returns a data URL representing the file's data. If an error happened during the read, the adequate exception is sent.
Return value
An DOMString
representing the file's data as a data URL.
Exceptions
The following exceptions can be raised by this method:
NotFoundError
- is raised when the resource represented by the DOM
Blob
or File
cannot be found, e. g. because it has been erased. SecurityError
- is raised when one of the following problematic situation is detected:
- the resource has been modified by a third party;
- too many read are performed simultaneously;
- the file pointed by the resource is unsafe for a use from the Web (like it is a system file).
NotReadableError
- is raised when the resource cannot be read due to a permission problem, like a concurrent lock.
EncodingError
- is raised when the resource is a data URL and exceed the limit length defined by each browser.
*/
String readAsDataURL(Blob blob);
/**
* This methods reads the specified blob's contents. When the read operation is finished, it returns a DOMString
containing the file represented as a text string. The optional encoding
parameter indicates the encoding to be used. If not present, the method will apply a detection algorithm for it. If an error happened during the read, the adequate exception is sent.
Parameters
Return value
A DOMString
containing the raw binary data from the resource
Exceptions
The following exceptions can be raised by this method:
NotFoundError
- is raised when the resource represented by the DOM
Blob
or File
cannot be found, e. g. because it has been erased. SecurityError
- is raised when one of the following problematic situation is detected:
- the resource has been modified by a third party;
- two many read are performed simultaneously;
- the file pointed by the resource is unsafe for a use from the Web (like it is a system file).
NotReadableError
- is raised when the resource cannot be read due to a permission problem, like a concurrent lock.
*/
String readAsText(Blob blob);
/**
* This methods reads the specified blob's contents. When the read operation is finished, it returns a DOMString
containing the file represented as a text string. The optional encoding
parameter indicates the encoding to be used. If not present, the method will apply a detection algorithm for it. If an error happened during the read, the adequate exception is sent.
Parameters
Return value
A DOMString
containing the raw binary data from the resource
Exceptions
The following exceptions can be raised by this method:
NotFoundError
- is raised when the resource represented by the DOM
Blob
or File
cannot be found, e. g. because it has been erased. SecurityError
- is raised when one of the following problematic situation is detected:
- the resource has been modified by a third party;
- two many read are performed simultaneously;
- the file pointed by the resource is unsafe for a use from the Web (like it is a system file).
NotReadableError
- is raised when the resource cannot be read due to a permission problem, like a concurrent lock.
*/
String readAsText(Blob blob, String encoding);
}