From 074785cea106179cb3305637055ab0a009ca74f2 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:42:52 -0500 Subject: initial commit --- files/pt-br/web/api/blob/blob/index.html | 65 +++++++++++++++ files/pt-br/web/api/blob/index.html | 130 ++++++++++++++++++++++++++++++ files/pt-br/web/api/blob/size/index.html | 60 ++++++++++++++ files/pt-br/web/api/blob/slice/index.html | 115 ++++++++++++++++++++++++++ files/pt-br/web/api/blob/type/index.html | 68 ++++++++++++++++ 5 files changed, 438 insertions(+) create mode 100644 files/pt-br/web/api/blob/blob/index.html create mode 100644 files/pt-br/web/api/blob/index.html create mode 100644 files/pt-br/web/api/blob/size/index.html create mode 100644 files/pt-br/web/api/blob/slice/index.html create mode 100644 files/pt-br/web/api/blob/type/index.html (limited to 'files/pt-br/web/api/blob') diff --git a/files/pt-br/web/api/blob/blob/index.html b/files/pt-br/web/api/blob/blob/index.html new file mode 100644 index 0000000000..fbb8b121c5 --- /dev/null +++ b/files/pt-br/web/api/blob/blob/index.html @@ -0,0 +1,65 @@ +--- +title: Blob +slug: Web/API/Blob/Blob +translation_of: Web/API/Blob/Blob +--- +

{{APIRef("File API")}}

+ +

Blob()

+ +

 

+ +

Retorna um novo objeto Blob criado, cujo o conteúdo consiste na concatenação de um array de valores estabelecidos no parâmetro da função.

+ +

Syntaxe

+ +
var aBlob = new Blob( array[, options]);
+
+ +

Parâmetros

+ + + +

Exemplo

+ +
var aFileParts = ['<a id="a"><b id="b">hey!</b></a>']; // an array consisting of a single DOMString
+var oMyBlob = new Blob(aFileParts, {type : 'text/html'}); // the blob
+ +

Especificação

+ + + + + + + + + + + + + + +
EspecificaçãoStatusComentário
{{SpecName('File API', '#constructorBlob', 'Blob()')}}{{Spec2('File API')}}Definição inicial.
+ +

Compatibilidade com navegadores

+ + + +

{{Compat("api.Blob.Blob")}}

+ +

Veja também

+ + + +

 

diff --git a/files/pt-br/web/api/blob/index.html b/files/pt-br/web/api/blob/index.html new file mode 100644 index 0000000000..f976675a1a --- /dev/null +++ b/files/pt-br/web/api/blob/index.html @@ -0,0 +1,130 @@ +--- +title: Blob +slug: Web/API/Blob +translation_of: Web/API/Blob +--- +

{{ APIRef("File API") }}

+ +

Sumário

+ +

Um objeto Blob representa um objeto do tipo arquivo, com  dados brutos imutáveis. Blobs representam dados que não estão necessariamente em um formato JavaScript nativo. A interface {{ domxref("File") }} é baseada no Blob, herdando funcionalidade blob e expandindo-o para suportar arquivos no sistema do usuário.

+ +

Para construir um Blob a partir de outro objeto ou dado não-blob , utilize o construtor {{domxref("Blob.Blob","Blob()")}}. Para criar um blob que contém um subconjunto de dados de outro blob, use o método {{domxref("Blob.slice()", "slice()")}}. Para obter um objeto Blob de um arquivo no sistema de arquivos do usuário, veja a documentação {{domxref("File")}}.

+ +

The APIs accepting Blob objects are also listed on the {{domxref("File")}} documentation.

+ +
+

Nota: O método slice() usava inicialmente length como segundo argumento para indicar o numero de bytes a copiar no novo Blob.  Se você especificou valores de maneira que start + length excederam o tamanho do Blob de origem, o Blob retornado contém dados a partir do início do índice até o final do Blob de origem.

+
+ +
Nota:  Esteja ciente que o método slice() possui prefixos de fornecedores em alguns navegadores e versões: blob.mozSlice() para Firefox 12 e anteriores, e blob.webkitSlice() para Safari. Uma versão antiga do método slice(), sem prefixos de fornecedor, tem semântica diferente, e portanto é obsoleta. O suporta para blob.mozSlice() foi descontinuado a partir do Firefox 30.
+ +

Construtor

+ +
+
{{domxref("Blob.Blob", "Blob(blobParts[, opções])")}}
+
Retorna um novo Blob object cujo conteúdo consiste na concatenação do array de valores passados por parâmentro.
+
+ +

Propriedades

+ +
+
{{domxref("Blob.size")}} {{readonlyinline}}
+
Tamanho em bytes dos dados contidos no objeto Blob.
+
{{domxref("Blob.type")}} {{readonlyinline}}
+
Uma string que indica o MIME type dos dados no Blob. Se o tipo é desconhecido, então retorna uma string vazia.
+
+ +

Métodos

+ +
+
{{domxref("Blob.slice()", "Blob.slice([start[, end[, contentType]]])")}}
+
Retorna um novo  Blob object contendo dados em no intervalo de bytes especificado do Blob de origem.
+
+ +

Exemplos

+ +

Exemplos de uso do construtor Blob

+ +

O código a seguir:

+ +
var aFileParts = ['<a id="a"><b id="b">hey!</b></a>'];
+var oMyBlob = new Blob(aFileParts, {type : 'text/html'}); // o blob
+
+ +

equivale a:

+ +
var oBuilder = new BlobBuilder();
+var aFileParts = ['<a id="a"><b id="b">hey!</b></a>'];
+oBuilder.append(aFileParts[0]);
+var oMyBlob = oBuilder.getBlob('text/xml'); // o blob
+
+ +
+

O {{ domxref("BlobBuilder") }} oferece outra maneira para criar Blobs, mas é depreciado e não deveria mais ser usado.

+
+ +

Exemplo para criar uma URL para uma array tipada usando blob

+ +

O código a seguir:

+ +
var typedArray = GetTheTypedArraySomehow();
+var blob = new Blob([typedArray], {type: 'application/octet-binary'}); // passe um MIME-type útil aqui
+var url = URL.createObjectURL(blob);
+// url será algo do tipo: blob:d3958f5c-0777-0845-9dcf-2cb28783acaf
+// agora você pode usar a URL em qualquer contexto em que URLs regulares podem ser usadas, por exemplo: img.src, etc.
+
+ +

Exemplo de Extração de Dados de Um Blob

+ +

O único jeito de ler o conteúdo de um Blob é usando {{domxref("FileReader")}}. O código a seguir lê o conteudo de um Blob como um Array.

+ +
var reader = new FileReader();
+reader.addEventListener("loadend", function() {
+   // reader.result contém o conteúdo do blob como uma array tipada
+});
+reader.readAsArrayBuffer(blob);
+ +

Ao usar outros métodos de {{domxref("FileReader")}}, é possível ler o conteúdo de um Blob como uma string ou como uma data URL.

+ +

Especificações

+ + + + + + + + + + + + + + +
EspecificaçõesStatusComentário
{{SpecName('File API','#blob','Blob')}}{{Spec2('File API')}}Definição inicial.
+ +

Compatibilidade de Browser

+ + + +

{{Compat("api.Blob")}}

+ +

Notas para Gecko

+ +

Anterior ao Gecko 12.0 {{ geckoRelease("12.0") }}, havia um bug que afetava o comportamento do {{ manch("slice") }}; que não funcionava para as posições start e end fora do intervalo de valores assinados como 64-bit; este bug foi corrigido para dar suporte a valores assinados como 64-bit.

+ +

Chrome Code - Disponibilidade de Escopo

+ +

No escopo JSM, Blob é disponivel sem a necessidade de nada especial.

+ +

No escopo Bootstrap, ele deve ser importado como tal:

+ +
const {Blob, Services} = Cu.import('resource://gre/modules/Services.jsm', {});
+ +

Veja Também

+ + diff --git a/files/pt-br/web/api/blob/size/index.html b/files/pt-br/web/api/blob/size/index.html new file mode 100644 index 0000000000..f73f76dca2 --- /dev/null +++ b/files/pt-br/web/api/blob/size/index.html @@ -0,0 +1,60 @@ +--- +title: Blob.size +slug: Web/API/Blob/size +translation_of: Web/API/Blob/size +--- +
{{APIRef("File API")}}
+ +

A propriedade Blob.size retorna o tamanho em bytes de {{domxref("Blob")}} ou um {{domxref("File")}}.

+ +

Syntaxe

+ +
var sizeInBytes = blob.size
+
+ +

Valor

+ +

Um número.

+ +

Exempl0

+ +
// fileInput é um HTMLInputElement: <input type="file" multiple id="myfileinput">
+var fileInput = document.getElementById("myfileinput");
+
+// files é um objeto FileList (similiar ao NodeList)
+var files = fileInput.files;
+
+for (var i = 0; i < files.length; i++) {
+  console.log(files[i].name + " has a size of " + files[i].size + " Bytes");
+}
+ +

Especificações

+ + + + + + + + + + + + + + +
EspecificaçãoStatusComentário
{{SpecName('File API', '#dfn-size', 'size')}}{{Spec2('File API')}}Definição inicial.
+ +

Compatibilidade com navegadores

+ +
+ + +

{{Compat("api.Blob.size")}}

+
+ +

Veja também

+ + diff --git a/files/pt-br/web/api/blob/slice/index.html b/files/pt-br/web/api/blob/slice/index.html new file mode 100644 index 0000000000..a6f44cfebd --- /dev/null +++ b/files/pt-br/web/api/blob/slice/index.html @@ -0,0 +1,115 @@ +--- +title: Blob.slice() +slug: Web/API/Blob/slice +translation_of: Web/API/Blob/slice +--- +
{{APIRef("File API")}}
+ +

O método Blob.slice() é usado para criar um novo {{domxref("Blob")}} object  contendo os dados no intervalo especificado de bytes da fonte {{domxref("Blob")}}.

+ +
Nota: Esteja ciente de que o método slice () tem prefixos de fornecedores em alguns navegadores e versões: blob.mozSlice () para Firefox 12 e anteriores e blob.webkitSlice () no Safari. Uma versão antiga do método slice (), sem prefixos de fornecedor, tinha uma semântica diferente e é obsoleta
+ +

Sintaxe

+ +
let blob = instanceOfBlob.slice([start [, end [, contentType]]]);
+ +

Parâmetros

+ +
+
start {{optional_inline}}
+
An index into the {{domxref("Blob")}} indicating the first byte to include in the new {{domxref("Blob")}}. If you specify a negative value, it's treated as an offset from the end of the string toward the beginning. For example, -10 would be the 10th from last byte in the {{domxref("Blob")}}. The default value is 0. If you specify a value for start that is larger than the size of the source {{domxref("Blob")}}, the returned {{domxref("Blob")}} has size 0 and contains no data.
+
end {{optional_inline}}
+
An index into the {{domxref("Blob")}} indicating the first byte that will *not* be included in the new {{domxref("Blob")}} (i.e. the byte exactly at this index is not included). If you specify a negative value, it's treated as an offset from the end of the string toward the beginning. For example, -10 would be the 10th from last byte in the {{domxref("Blob")}}. The default value is size.
+
contentType {{optional_inline}}
+
The content type to assign to the new {{domxref("Blob")}}; this will be the value of its type property. The default value is an empty string.
+
+ +

Return value

+ +

A new {{domxref("Blob")}} object containing the specified data from the source {{domxref("Blob")}}.

+ +

Specifications

+ + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName("File API", "#dfn-slice", "Blob.slice()")}}{{Spec2("File API")}}Initial definition
+ +

Browser compatibility

+ +

{{CompatibilityTable}}

+ +
+ + + + + + + + + + + + + + + + + + + + + +
FeatureChromeEdgeFirefox (Gecko)Internet ExplorerOperaSafari (WebKit)
Basic support10 {{property_prefix("webkit")}} [1]
+ 21
{{CompatVersionUnknown}}5 {{property_prefix("moz")}} [1]
+ 13 [2]
1012 [1]5.1 {{property_prefix("webkit")}} [3]
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
FeatureAndroidEdgeFirefox Mobile (Gecko)IE PhoneOpera MobileSafari Mobile
Basic support{{CompatUnknown}}{{CompatVersionUnknown}}{{CompatGeckoMobile("13.0")}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}
+
+ +

[1] The slice() method had initially taken length as the second argument to indicate the number of bytes to include in the new Blob. If you specified values such that start + length exceeded the size of the source Blob, the returned Blob contained data from the start index to the end of the source Blob. That version of the slice() was implemented in Firefox 4, WebKit, and Opera 11.10. However, since that syntax is differed from Array.slice() and String.slice(), Gecko and WebKit removed support and added support for the new syntax as Blob.slice()/Blob.webkitSlice.

+ +

[2] Prior to Gecko 12.0 {{geckoRelease("12.0")}}, there was a bug that affected the behavior of Blob.slice(); it did not work for start and end positions outside the range of signed 64-bit values; it has now been fixed to support unsigned 64-bit values.

+ +

[3] This was implemented in 534.29.

+ +

See also

+ + diff --git a/files/pt-br/web/api/blob/type/index.html b/files/pt-br/web/api/blob/type/index.html new file mode 100644 index 0000000000..789aa0c9c9 --- /dev/null +++ b/files/pt-br/web/api/blob/type/index.html @@ -0,0 +1,68 @@ +--- +title: Blob.type +slug: Web/API/Blob/type +translation_of: Web/API/Blob/type +--- +
{{APIRef("File API")}}
+ +

A propriedade type de um objeto Blob fornece MIME type do arquivo. Ela retorna uma string vazia se o tipo não puder ser determinado.

+ +

Syntaxe

+ +
var mimetype = instanceOfFile.type
+ +

Valor

+ +

Uma string

+ +

Exemplo

+ +
var i, fileInput, files, allowedFileTypes;
+
+// fileInput é um HTMLInputElement: <input type="file" multiple id="myfileinput">
+fileInput = document.getElementById("myfileinput");
+
+// files é um objeto FileList (similiar ao NodeList)
+files = fileInput.files;
+
+// nossa aplicação permite apenas imagens dos tipos *.png, *.jpeg and *.gif
+allowedFileTypes = ["image/png", "image/jpeg", "image/gif"];
+
+for (i = 0; i < files.length; i++) {
+  // Testa se file.type é um tipo de arquivo permitido.
+  if (allowedFileTypes.indexOf(files[i].type) > -1) {
+    // file type é um dos tipos permitidos. Código aqui.
+  }
+});
+
+ +

Especificações

+ + + + + + + + + + + + + + +
EspecificaçãoStatusComentário
{{SpecName('File API', '#dfn-type', 'type')}}{{Spec2('File API')}}Definição inicial.
+ +

Compatibilidade com navegadores

+ +
+ + +

{{Compat("api.Blob.type")}}

+
+ +

Veja também

+ + -- cgit v1.2.3-54-g00ecf