Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
deno
提交
deec1b9b
D
deno
项目概览
张重言
/
deno
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
deno
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
deec1b9b
编写于
8月 01, 2019
作者:
T
Tomohito Nakayama
提交者:
Ryan Dahl
8月 01, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Implement function convertLineEndingsToNative in blob.ts (#2695)
based on
https://w3c.github.io/FileAPI/#convert-line-endings-to-native
上级
3971dcfe
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
56 addition
and
3 deletion
+56
-3
js/blob.ts
js/blob.ts
+47
-3
js/blob_test.ts
js/blob_test.ts
+9
-0
未找到文件。
js/blob.ts
浏览文件 @
deec1b9b
...
...
@@ -2,13 +2,57 @@
import
*
as
domTypes
from
"
./dom_types
"
;
import
{
containsOnlyASCII
,
hasOwnProperty
}
from
"
./util
"
;
import
{
TextEncoder
}
from
"
./text_encoding
"
;
import
{
build
}
from
"
./build
"
;
export
const
bytesSymbol
=
Symbol
(
"
bytes
"
);
function
convertLineEndingsToNative
(
s
:
string
):
string
{
// TODO(qti3e) Implement convertLineEndingsToNative.
// https://w3c.github.io/FileAPI/#convert-line-endings-to-native
return
s
;
let
nativeLineEnd
=
build
.
os
==
"
win
"
?
"
\r\n
"
:
"
\n
"
;
let
position
=
0
;
let
collectionResult
=
collectSequenceNotCRLF
(
s
,
position
);
let
token
=
collectionResult
.
collected
;
position
=
collectionResult
.
newPosition
;
let
result
=
token
;
while
(
position
<
s
.
length
)
{
let
c
=
s
.
charAt
(
position
);
if
(
c
==
"
\r
"
)
{
result
+=
nativeLineEnd
;
position
++
;
if
(
position
<
s
.
length
&&
s
.
charAt
(
position
)
==
"
\n
"
)
{
position
++
;
}
}
else
if
(
c
==
"
\n
"
)
{
position
++
;
result
+=
nativeLineEnd
;
}
collectionResult
=
collectSequenceNotCRLF
(
s
,
position
);
token
=
collectionResult
.
collected
;
position
=
collectionResult
.
newPosition
;
result
+=
token
;
}
return
result
;
}
function
collectSequenceNotCRLF
(
s
:
string
,
position
:
number
):
{
collected
:
string
;
newPosition
:
number
}
{
const
start
=
position
;
for
(
let
c
=
s
.
charAt
(
position
);
position
<
s
.
length
&&
!
(
c
==
"
\r
"
||
c
==
"
\n
"
);
c
=
s
.
charAt
(
++
position
)
);
return
{
collected
:
s
.
slice
(
start
,
position
),
newPosition
:
position
};
}
function
toUint8Arrays
(
...
...
js/blob_test.ts
浏览文件 @
deec1b9b
...
...
@@ -50,4 +50,13 @@ test(function blobShouldNotThrowError(): void {
assertEquals
(
hasThrown
,
false
);
});
test
(
function
nativeEndLine
():
void
{
const
options
:
object
=
{
ending
:
"
native
"
};
let
blob
=
new
Blob
([
"
Hello
\n
World
"
],
options
);
assertEquals
(
blob
.
size
,
Deno
.
build
.
os
===
"
win
"
?
12
:
11
);
});
// TODO(qti3e) Test the stored data in a Blob after implementing FileReader API.
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录