mirror of
https://github.com/zoriya/srt-webvtt.git
synced 2026-06-05 18:34:21 +00:00
added toTypedArray to the class
This commit is contained in:
@@ -24,6 +24,14 @@ class WebVTTConverter {
|
|||||||
.replace(/(\d\d:\d\d:\d\d),(\d\d\d)/g, '$1.$2') + '\r\n\r\n';
|
.replace(/(\d\d:\d\d:\d\d),(\d\d\d)/g, '$1.$2') + '\r\n\r\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
toTypedArray(str) {
|
||||||
|
const result = [];
|
||||||
|
str.split().forEach((each, index) => {
|
||||||
|
result.push(parseInt(str.substring(index, index + 2), 16));
|
||||||
|
});
|
||||||
|
return Uint8Array.from(result);
|
||||||
|
}
|
||||||
|
|
||||||
getURL() {
|
getURL() {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (!(this.resource instanceof Blob)) return reject('Expecting resource to be a Blob but something else found.');
|
if (!(this.resource instanceof Blob)) return reject('Expecting resource to be a Blob but something else found.');
|
||||||
@@ -33,6 +41,7 @@ class WebVTTConverter {
|
|||||||
.then(buffer => {
|
.then(buffer => {
|
||||||
const utf8str = new TextDecoder('utf-8').decode(buffer);
|
const utf8str = new TextDecoder('utf-8').decode(buffer);
|
||||||
const vttString = 'WEBVTT FILE\r\n\r\n';
|
const vttString = 'WEBVTT FILE\r\n\r\n';
|
||||||
|
console.log(this.toTypedArray(vttString.concat(utf8str)));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user