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
Roque
jio
Commits
491b6328
Commit
491b6328
authored
Mar 11, 2014
by
Tristan Cavelier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
localstorage getAttachment binary reading bug fix
parent
c7f3b357
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
8 deletions
+17
-8
src/jio.storage/localstorage.js
src/jio.storage/localstorage.js
+17
-8
No files found.
src/jio.storage/localstorage.js
View file @
491b6328
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
*/
*/
/*jslint indent: 2, maxlen: 80, sloppy: true, nomen: true, regexp: true */
/*jslint indent: 2, maxlen: 80, sloppy: true, nomen: true, regexp: true */
/*global jIO, localStorage, setTimeout, window, define,
/*global jIO, localStorage, setTimeout, window, define,
Blob, Uint8Array,
exports, require */
exports, require */
/**
/**
...
@@ -286,7 +286,7 @@
...
@@ -286,7 +286,7 @@
* @param {Object} options The command options
* @param {Object} options The command options
*/
*/
LocalStorage
.
prototype
.
getAttachment
=
function
(
command
,
param
)
{
LocalStorage
.
prototype
.
getAttachment
=
function
(
command
,
param
)
{
var
doc
;
var
doc
,
i
,
uint8array
,
binarystring
;
doc
=
this
.
_storage
.
getItem
(
this
.
_localpath
+
"
/
"
+
param
.
_id
);
doc
=
this
.
_storage
.
getItem
(
this
.
_localpath
+
"
/
"
+
param
.
_id
);
if
(
doc
===
null
)
{
if
(
doc
===
null
)
{
return
command
.
error
(
return
command
.
error
(
...
@@ -305,13 +305,22 @@
...
@@ -305,13 +305,22 @@
);
);
}
}
// Storing data twice in binarystring and in uint8array (in memory)
// is not a problem here because localStorage <= 5MB
binarystring
=
this
.
_storage
.
getItem
(
this
.
_localpath
+
"
/
"
+
param
.
_id
+
"
/
"
+
param
.
_attachment
)
||
""
;
uint8array
=
new
Uint8Array
(
binarystring
.
length
);
for
(
i
=
0
;
i
<
binarystring
.
length
;
i
+=
1
)
{
uint8array
[
i
]
=
binarystring
.
charCodeAt
(
i
);
// mask `& 0xFF` not necessary
}
uint8array
=
new
Blob
([
uint8array
],
{
"
type
"
:
doc
.
_attachments
[
param
.
_attachment
].
content_type
||
""
});
command
.
success
({
command
.
success
({
"
data
"
:
this
.
_storage
.
getItem
(
"
data
"
:
uint8array
,
this
.
_localpath
+
"
/
"
+
param
.
_id
+
"
digest
"
:
doc
.
_attachments
[
param
.
_attachment
].
digest
"
/
"
+
param
.
_attachment
)
||
""
,
"
digest
"
:
doc
.
_attachments
[
param
.
_attachment
].
digest
,
"
content_type
"
:
doc
.
_attachments
[
param
.
_attachment
].
content_type
||
""
});
});
};
};
...
...
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