Skip to content

Commit c8c3c57

Browse files
committed
Making the stream indirect length object object stream aware.
1 parent f8c990e commit c8c3c57

File tree

2 files changed

+38
-32
lines changed

2 files changed

+38
-32
lines changed

src/CosDoc.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,8 @@ function cosDocGetObject(doc::CosDocImpl, stm::CosNullType,
281281
ref::CosIndirectObjectRef, locObj::CosObjectLoc)
282282
if (locObj.obj === CosNull)
283283
seek(doc, locObj.loc)
284-
locObj.obj = parse_indirect_obj(doc.ps, doc.hoffset, doc.xref)
284+
locObj.obj = parse_indirect_obj(doc.ps, doc.hoffset, doc.xref,
285+
(x, y, z)->cosDocGetObject(doc, x, y, z))
285286
# Decrypt here
286287
decrypt!(doc.secHandler, locObj.obj)
287288
attach_object(doc, locObj.obj)

src/CosReader.jl

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -246,41 +246,43 @@ function ensure_line_feed_eol(ps::IO)
246246
end
247247
end
248248

249-
#=
250-
Read the internal stream data and externalize to a temp file.
251-
If it's already an externalized stream then false is returned.
252-
The value can be stored in the stream object attribute so that the reverse
253-
process will be carried out for serialization.
254-
=#
255-
function read_internal_stream_data(ps::IO, extent::CosDict, len::Int)
256-
get(extent, cn"F") != CosNull && return false
257-
249+
function read_internal_stream_data(extent::CosDict, data)
258250
(path, io) = get_tempfilepath()
259251
try
260-
data = read(ps, len)
261252
write(io, data)
262253
finally
263254
util_close(io)
264255
end
265256

266257
#Ensuring all the data is written to a file
267258
set!(extent, cn"F", CosLiteralString(path))
268-
269259
filter = get(extent, cn"Filter")
270260
if (filter != CosNull)
271261
set!(extent, cn"FFilter", filter)
272262
set!(extent, cn"Filter", CosNull)
273263
end
274-
275264
parms = get(extent, cn"DecodeParms")
276265
if (parms != CosNull)
277266
set!(extent, cn"FDecodeParms", parms)
278267
set!(extent, cn"DecodeParms", CosNull)
279268
end
280-
281269
return true
282270
end
283271

272+
#=
273+
Read the internal stream data and externalize to a temp file.
274+
If it's already an externalized stream then false is returned.
275+
The value can be stored in the stream object attribute so that the reverse
276+
process will be carried out for serialization.
277+
=#
278+
function read_internal_stream_data(ps::IO, extent::CosDict, len::Int)
279+
get(extent, cn"F") != CosNull && return false
280+
data = read(ps, len)
281+
#Now eat away the ENDSTREAM token
282+
chomp_space!(ps)
283+
skipv(ps, ENDSTREAM)
284+
return read_internal_stream_data(extent, data)
285+
end
284286

285287
mutable struct CosObjectLoc
286288
loc::Int
@@ -292,49 +294,50 @@ end
292294
process_stream_length(stmlen::CosInt,
293295
ps::IO,
294296
hoffset::Int,
295-
xref::Dict{CosIndirectObjectRef, CosObjectLoc})=stmlen
297+
xref::Dict{CosIndirectObjectRef, CosObjectLoc},
298+
pred)=stmlen
296299

297300
function process_stream_length(stmlen::CosIndirectObjectRef,
298301
ps::IO,
299302
hoffset::Int,
300-
xref::Dict{CosIndirectObjectRef, CosObjectLoc})
303+
xref::Dict{CosIndirectObjectRef, CosObjectLoc},
304+
pred)
301305
cosObjectLoc = xref[stmlen]
302-
if (cosObjectLoc.obj === CosNull)
303-
seek(ps, cosObjectLoc.loc + hoffset)
304-
cosObjectLoc.obj = parse_indirect_obj(ps, hoffset, xref)
306+
if cosObjectLoc.obj === CosNull
307+
if cosObjectLoc.stm === CosNull
308+
seek(ps, cosObjectLoc.loc + hoffset)
309+
cosObjectLoc.obj = parse_indirect_obj(ps, hoffset, xref)
310+
else
311+
cosObjectLoc.obj = pred(cosObjectLoc.stm, stmlen, cosObjectLoc)
312+
end
305313
end
306314
return cosObjectLoc.obj
307315
end
308316

309317
function postprocess_indirect_object(ps::IO, hoffset::Int, obj::CosDict,
310318
xref::Dict{CosIndirectObjectRef,
311-
CosObjectLoc})
319+
CosObjectLoc}, pred)
312320
if locate_keyword!(ps, STREAM) == 0
313321
ensure_line_feed_eol(ps)
314322
pos = position(ps)
315323

316324
stmlen = get(obj, cn"Length")
317325

318-
lenobj = process_stream_length(stmlen, ps, hoffset, xref)
319-
320-
len = get(lenobj)
326+
lenobj = process_stream_length(stmlen, ps, hoffset, xref, pred)
321327

322328
if (lenobj != stmlen)
323329
set!(obj, cn"Length", lenobj)
324330
end
325331

332+
len = get(lenobj)
333+
326334
seek(ps, pos)
327335

328336
# Here you can make sure file data is decoded into a file
329-
# later it can be made into a memory based on size etc.
337+
# later it can be taken into memory based on size etc.
330338
# Since, these are temporary files the spec is system file only
331339
isInternal = read_internal_stream_data(ps, obj, len)
332-
333340
obj = CosStream(obj, isInternal)
334-
335-
#Now eat away the ENDSTREAM token
336-
chomp_space!(ps)
337-
skipv(ps,ENDSTREAM)
338341
obj = createIfObjectStream(obj)
339342
end
340343
return obj
@@ -343,11 +346,13 @@ end
343346
postprocess_indirect_object(ps::IO,
344347
hoffset::Int,
345348
obj::CosObject,
346-
xref::Dict{CosIndirectObjectRef, CosObjectLoc}) = obj
349+
xref::Dict{CosIndirectObjectRef, CosObjectLoc},
350+
pred) = obj
347351

348352
function parse_indirect_obj(ps::IO,
349353
hoffset::Int,
350-
xref::Dict{CosIndirectObjectRef, CosObjectLoc})
354+
xref::Dict{CosIndirectObjectRef, CosObjectLoc},
355+
pred=(x...)->nothing)
351356
chomp_space!(ps)
352357
objn = parse_unsignednumber(ps).val
353358
chomp_space!(ps)
@@ -356,7 +361,7 @@ function parse_indirect_obj(ps::IO,
356361
skipv(ps, OBJ)
357362
obj = parse_value(ps)
358363
chomp_space!(ps)
359-
obj = postprocess_indirect_object(ps, hoffset, obj, xref)
364+
obj = postprocess_indirect_object(ps, hoffset, obj, xref, pred)
360365
chomp_space!(ps)
361366
skipv(ps,ENDOBJ)
362367
return CosIndirectObject(objn, genn, obj)

0 commit comments

Comments
 (0)