Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
jio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Aurélien Vermylen
jio
Commits
ab268eb8
Commit
ab268eb8
authored
7 years ago
by
Aurel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add tristan lib to simulate HTML5 Blobl & FileReader
parent
6148339d
clearroad
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
114 additions
and
0 deletions
+114
-0
nodejs/node_modules/html5.js
nodejs/node_modules/html5.js
+114
-0
No files found.
nodejs/node_modules/html5.js
0 → 100644
View file @
ab268eb8
(
function
(
env
)
{
"
use strict
"
;
/*! html5.node.js Version 1.0.0
Copyright (c) 2017 Tristan Cavelier <t.cavelier@free.fr>
This program is free software. It comes without any warranty, to
the extent permitted by applicable law. You can redistribute it
and/or modify it under the terms of the Do What The Fuck You Want
To Public License, Version 2, as published by Sam Hocevar. See
http://www.wtfpl.net/ for more details. */
// provides:
// _html5_weakmap
// EventTarget
// Blob
// FileReader
// function include(path) { return eval(require("fs").readFileSync(path).toString()); }
const
process
=
require
(
"
process
"
);
env
.
_html5_weakmap
=
new
WeakMap
();
function
EventTarget
()
{
env
.
_html5_weakmap
.
set
(
this
,
Object
.
create
(
null
));
}
EventTarget
.
prototype
.
addEventListener
=
function
(
type
,
listener
)
{
if
(
typeof
listener
!==
"
function
"
)
return
;
const
em
=
env
.
_html5_weakmap
.
get
(
this
);
type
=
""
+
type
;
if
(
em
[
type
])
em
[
type
].
push
(
listener
);
else
em
[
type
]
=
[
listener
];
};
EventTarget
.
prototype
.
removeEventListener
=
function
(
type
,
listener
)
{
if
(
typeof
listener
!==
"
function
"
)
return
;
const
em
=
env
.
_html5_weakmap
.
get
(
this
);
var
i
=
0
,
listeners
=
em
[
type
];
type
=
""
+
type
;
if
(
listeners
)
for
(;
i
<
listeners
.
length
;
++
i
)
if
(
listeners
[
i
]
===
listener
)
{
if
(
listeners
.
length
===
1
)
{
delete
em
[
type
];
return
;
}
listeners
.
splice
(
i
,
1
);
return
;
}
};
EventTarget
.
prototype
.
dispatchEvent
=
function
(
event
)
{
const
type
=
""
+
event
.
type
,
em
=
env
.
_html5_weakmap
.
get
(
this
),
ontype
=
"
on
"
+
type
;
var
i
=
0
,
listeners
;
if
(
typeof
this
[
ontype
]
===
"
function
"
)
{
try
{
this
[
ontype
](
event
);
}
catch
(
ignore
)
{}
}
if
(
listeners
=
em
[
type
])
for
(;
i
<
listeners
.
length
;
++
i
)
{
try
{
listeners
[
i
](
event
);
}
catch
(
ignore
)
{}
}
};
env
.
EventTarget
=
EventTarget
;
function
Blob
(
blobParts
,
options
)
{
// https://developer.mozilla.org/en-US/docs/Web/API/Blob
var
i
=
0
;
const
priv
=
{},
buffers
=
[];
env
.
_html5_weakmap
.
set
(
this
,
priv
);
for
(;
i
<
blobParts
.
length
;
++
i
)
{
if
(
Buffer
.
isBuffer
(
blobParts
[
i
]))
{
buffers
.
push
(
blobParts
[
i
]);
}
else
if
(
blobParts
[
i
]
instanceof
Blob
)
{
buffers
.
push
(
env
.
_html5_weakmap
.
get
(
blobParts
[
i
]).
data
);
}
else
if
(
blobParts
[
i
]
instanceof
ArrayBuffer
)
{
buffers
.
push
(
new
Buffer
(
new
Uint8Array
(
blobParts
[
i
])));
}
else
{
buffers
.
push
(
new
Buffer
(
""
+
blobParts
[
i
]));
}
}
priv
.
data
=
Buffer
.
concat
(
buffers
);
Object
.
defineProperty
(
this
,
"
size
"
,
{
enumerable
:
true
,
value
:
priv
.
data
.
length
});
Object
.
defineProperty
(
this
,
"
type
"
,
{
enumerable
:
true
,
value
:
options
?
""
+
(
options
.
type
||
""
)
:
""
});
}
Blob
.
prototype
.
size
=
0
;
Blob
.
prototype
.
type
=
""
;
Blob
.
prototype
.
slice
=
function
(
start
,
end
,
contentType
)
{
return
new
Blob
([
env
.
_html5_weakmap
.
get
(
this
).
data
.
slice
(
start
,
end
)],
{
type
:
contentType
});
};
env
.
Blob
=
Blob
;
function
FileReader
()
{
EventTarget
.
call
(
this
);
}
FileReader
.
prototype
=
Object
.
create
(
EventTarget
.
prototype
);
Object
.
defineProperty
(
FileReader
,
"
constructor
"
,
{
value
:
FileReader
});
FileReader
.
prototype
.
readAsText
=
function
(
blob
)
{
const
priv
=
env
.
_html5_weakmap
.
get
(
blob
);
const
text
=
priv
.
data
.
toString
();
const
event
=
Object
.
freeze
({
type
:
"
load
"
,
target
:
this
});
process
.
nextTick
(()
=>
{
this
.
result
=
text
;
this
.
dispatchEvent
(
event
);
});
};
FileReader
.
prototype
.
readAsArrayBuffer
=
function
(
blob
)
{
const
priv
=
env
.
_html5_weakmap
.
get
(
blob
);
const
arrayBuffer
=
new
Uint8Array
(
priv
.
data
).
buffer
;
const
event
=
Object
.
freeze
({
type
:
"
load
"
,
target
:
this
});
process
.
nextTick
(()
=>
{
this
.
result
=
arrayBuffer
;
this
.
dispatchEvent
(
event
);
});
};
FileReader
.
prototype
.
readAsDataURL
=
function
(
blob
)
{
const
priv
=
env
.
_html5_weakmap
.
get
(
blob
);
const
dataUrl
=
"
data:
"
+
blob
.
type
+
"
;base64,
"
+
priv
.
data
.
toString
(
"
base64
"
);
const
event
=
Object
.
freeze
({
type
:
"
load
"
,
target
:
this
});
process
.
nextTick
(()
=>
{
this
.
result
=
dataUrl
;
this
.
dispatchEvent
(
event
);
});
};
env
.
FileReader
=
FileReader
;
}(
this
));
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment